@Test public void testSendRoleRequestErrorHandling () throws Exception { LinkedList<OFSwitchImpl> switches = new LinkedList<OFSwitchImpl>(); OFSwitchImpl sw1 = EasyMock.createMock(OFSwitchImpl.class); expect(sw1.getAttribute(IOFSwitch.SWITCH_SUPPORTS_NX_ROLE)) .andReturn(true); expect(sw1.sendNxRoleRequest(Role.MASTER, 123456)) .andThrow(new IOException()).once(); Channel channel1 = createMock(Channel.class); expect(sw1.getChannel()).andReturn(channel1); expect(channel1.close()).andReturn(null); switches.add(sw1); replay(sw1); roleChanger.sendRoleRequest(switches, Role.MASTER, 123456); verify(sw1); assertTrue(switches.isEmpty()); }
@LogMessageDoc(level="WARN", message="Failed to send role request message " + "to switch {switch}: {message}. Disconnecting", explanation="An I/O error occurred while attempting to change " + "the switch HA role.", recommendation=LogMessageDoc.CHECK_SWITCH) protected void sendRoleRequest(Collection<OFSwitchImpl> switches, Role role, long cookie) { Iterator<OFSwitchImpl> iter = switches.iterator(); while(iter.hasNext()) { OFSwitchImpl sw = iter.next(); try { Boolean supportsNxRole = (Boolean) sw.getAttribute(IOFSwitch.SWITCH_SUPPORTS_NX_ROLE); if ((supportsNxRole == null) || supportsNxRole) { sw.sendNxRoleRequest(role, cookie); } else { if (role == Role.SLAVE) { log.debug("Disconnecting switch {} that doesn't support " + "role request messages from a controller that went to SLAVE mode"); sw.getChannel().close(); iter.remove(); } } } catch (IOException e) { log.warn("Failed to send role request message " + "to switch {}: {}. Disconnecting", sw, e); sw.getChannel().close(); iter.remove(); } } }
RoleChanger { @LogMessageDoc(level="WARN", message="Failed to send role request message " + "to switch {switch}: {message}. Disconnecting", explanation="An I/O error occurred while attempting to change " + "the switch HA role.", recommendation=LogMessageDoc.CHECK_SWITCH) protected void sendRoleRequest(Collection<OFSwitchImpl> switches, Role role, long cookie) { Iterator<OFSwitchImpl> iter = switches.iterator(); while(iter.hasNext()) { OFSwitchImpl sw = iter.next(); try { Boolean supportsNxRole = (Boolean) sw.getAttribute(IOFSwitch.SWITCH_SUPPORTS_NX_ROLE); if ((supportsNxRole == null) || supportsNxRole) { sw.sendNxRoleRequest(role, cookie); } else { if (role == Role.SLAVE) { log.debug("Disconnecting switch {} that doesn't support " + "role request messages from a controller that went to SLAVE mode"); sw.getChannel().close(); iter.remove(); } } } catch (IOException e) { log.warn("Failed to send role request message " + "to switch {}: {}. Disconnecting", sw, e); sw.getChannel().close(); iter.remove(); } } } }
RoleChanger { @LogMessageDoc(level="WARN", message="Failed to send role request message " + "to switch {switch}: {message}. Disconnecting", explanation="An I/O error occurred while attempting to change " + "the switch HA role.", recommendation=LogMessageDoc.CHECK_SWITCH) protected void sendRoleRequest(Collection<OFSwitchImpl> switches, Role role, long cookie) { Iterator<OFSwitchImpl> iter = switches.iterator(); while(iter.hasNext()) { OFSwitchImpl sw = iter.next(); try { Boolean supportsNxRole = (Boolean) sw.getAttribute(IOFSwitch.SWITCH_SUPPORTS_NX_ROLE); if ((supportsNxRole == null) || supportsNxRole) { sw.sendNxRoleRequest(role, cookie); } else { if (role == Role.SLAVE) { log.debug("Disconnecting switch {} that doesn't support " + "role request messages from a controller that went to SLAVE mode"); sw.getChannel().close(); iter.remove(); } } } catch (IOException e) { log.warn("Failed to send role request message " + "to switch {}: {}. Disconnecting", sw, e); sw.getChannel().close(); iter.remove(); } } } RoleChanger(); }
RoleChanger { @LogMessageDoc(level="WARN", message="Failed to send role request message " + "to switch {switch}: {message}. Disconnecting", explanation="An I/O error occurred while attempting to change " + "the switch HA role.", recommendation=LogMessageDoc.CHECK_SWITCH) protected void sendRoleRequest(Collection<OFSwitchImpl> switches, Role role, long cookie) { Iterator<OFSwitchImpl> iter = switches.iterator(); while(iter.hasNext()) { OFSwitchImpl sw = iter.next(); try { Boolean supportsNxRole = (Boolean) sw.getAttribute(IOFSwitch.SWITCH_SUPPORTS_NX_ROLE); if ((supportsNxRole == null) || supportsNxRole) { sw.sendNxRoleRequest(role, cookie); } else { if (role == Role.SLAVE) { log.debug("Disconnecting switch {} that doesn't support " + "role request messages from a controller that went to SLAVE mode"); sw.getChannel().close(); iter.remove(); } } } catch (IOException e) { log.warn("Failed to send role request message " + "to switch {}: {}. Disconnecting", sw, e); sw.getChannel().close(); iter.remove(); } } } RoleChanger(); synchronized void submitRequest(Collection<OFSwitchImpl> switches, Role role); }
RoleChanger { @LogMessageDoc(level="WARN", message="Failed to send role request message " + "to switch {switch}: {message}. Disconnecting", explanation="An I/O error occurred while attempting to change " + "the switch HA role.", recommendation=LogMessageDoc.CHECK_SWITCH) protected void sendRoleRequest(Collection<OFSwitchImpl> switches, Role role, long cookie) { Iterator<OFSwitchImpl> iter = switches.iterator(); while(iter.hasNext()) { OFSwitchImpl sw = iter.next(); try { Boolean supportsNxRole = (Boolean) sw.getAttribute(IOFSwitch.SWITCH_SUPPORTS_NX_ROLE); if ((supportsNxRole == null) || supportsNxRole) { sw.sendNxRoleRequest(role, cookie); } else { if (role == Role.SLAVE) { log.debug("Disconnecting switch {} that doesn't support " + "role request messages from a controller that went to SLAVE mode"); sw.getChannel().close(); iter.remove(); } } } catch (IOException e) { log.warn("Failed to send role request message " + "to switch {}: {}. Disconnecting", sw, e); sw.getChannel().close(); iter.remove(); } } } RoleChanger(); synchronized void submitRequest(Collection<OFSwitchImpl> switches, Role role);  }