Merge branch 'master' of ssh://gerrit.onlab.us:29418/onos-next
Showing
6 changed files
with
70 additions
and
16 deletions
| ... | @@ -32,6 +32,8 @@ import org.onlab.onos.cluster.ClusterService; | ... | @@ -32,6 +32,8 @@ import org.onlab.onos.cluster.ClusterService; |
| 32 | import org.onlab.onos.cluster.ControllerNode; | 32 | import org.onlab.onos.cluster.ControllerNode; |
| 33 | import org.onlab.onos.cluster.NodeId; | 33 | import org.onlab.onos.cluster.NodeId; |
| 34 | import org.onlab.onos.mastership.MastershipService; | 34 | import org.onlab.onos.mastership.MastershipService; |
| 35 | +import org.onlab.onos.mastership.MastershipTerm; | ||
| 36 | +import org.onlab.onos.mastership.MastershipTermService; | ||
| 35 | import org.onlab.onos.net.AnnotationsUtil; | 37 | import org.onlab.onos.net.AnnotationsUtil; |
| 36 | import org.onlab.onos.net.DefaultAnnotations; | 38 | import org.onlab.onos.net.DefaultAnnotations; |
| 37 | import org.onlab.onos.net.DefaultDevice; | 39 | import org.onlab.onos.net.DefaultDevice; |
| ... | @@ -39,6 +41,7 @@ import org.onlab.onos.net.DefaultPort; | ... | @@ -39,6 +41,7 @@ import org.onlab.onos.net.DefaultPort; |
| 39 | import org.onlab.onos.net.Device; | 41 | import org.onlab.onos.net.Device; |
| 40 | import org.onlab.onos.net.Device.Type; | 42 | import org.onlab.onos.net.Device.Type; |
| 41 | import org.onlab.onos.net.DeviceId; | 43 | import org.onlab.onos.net.DeviceId; |
| 44 | +import org.onlab.onos.net.MastershipRole; | ||
| 42 | import org.onlab.onos.net.Port; | 45 | import org.onlab.onos.net.Port; |
| 43 | import org.onlab.onos.net.PortNumber; | 46 | import org.onlab.onos.net.PortNumber; |
| 44 | import org.onlab.onos.net.device.DeviceClockService; | 47 | import org.onlab.onos.net.device.DeviceClockService; |
| ... | @@ -89,6 +92,7 @@ import static com.google.common.base.Verify.verify; | ... | @@ -89,6 +92,7 @@ import static com.google.common.base.Verify.verify; |
| 89 | import static org.onlab.util.Tools.namedThreads; | 92 | import static org.onlab.util.Tools.namedThreads; |
| 90 | import static java.util.concurrent.Executors.newSingleThreadScheduledExecutor; | 93 | import static java.util.concurrent.Executors.newSingleThreadScheduledExecutor; |
| 91 | import static org.onlab.onos.store.device.impl.GossipDeviceStoreMessageSubjects.DEVICE_ADVERTISE; | 94 | import static org.onlab.onos.store.device.impl.GossipDeviceStoreMessageSubjects.DEVICE_ADVERTISE; |
| 95 | +import static org.onlab.onos.store.device.impl.GossipDeviceStoreMessageSubjects.DEVICE_REMOVE_REQ; | ||
| 92 | 96 | ||
| 93 | // TODO: give me a better name | 97 | // TODO: give me a better name |
| 94 | /** | 98 | /** |
| ... | @@ -160,6 +164,7 @@ public class GossipDeviceStore | ... | @@ -160,6 +164,7 @@ public class GossipDeviceStore |
| 160 | GossipDeviceStoreMessageSubjects.DEVICE_UPDATE, new InternalDeviceEventListener()); | 164 | GossipDeviceStoreMessageSubjects.DEVICE_UPDATE, new InternalDeviceEventListener()); |
| 161 | clusterCommunicator.addSubscriber( | 165 | clusterCommunicator.addSubscriber( |
| 162 | GossipDeviceStoreMessageSubjects.DEVICE_OFFLINE, new InternalDeviceOfflineEventListener()); | 166 | GossipDeviceStoreMessageSubjects.DEVICE_OFFLINE, new InternalDeviceOfflineEventListener()); |
| 167 | + clusterCommunicator.addSubscriber(DEVICE_REMOVE_REQ, new InternalRemoveRequestListener()); | ||
| 163 | clusterCommunicator.addSubscriber( | 168 | clusterCommunicator.addSubscriber( |
| 164 | GossipDeviceStoreMessageSubjects.DEVICE_REMOVED, new InternalDeviceRemovedEventListener()); | 169 | GossipDeviceStoreMessageSubjects.DEVICE_REMOVED, new InternalDeviceRemovedEventListener()); |
| 165 | clusterCommunicator.addSubscriber( | 170 | clusterCommunicator.addSubscriber( |
| ... | @@ -715,14 +720,48 @@ public class GossipDeviceStore | ... | @@ -715,14 +720,48 @@ public class GossipDeviceStore |
| 715 | 720 | ||
| 716 | @Override | 721 | @Override |
| 717 | public synchronized DeviceEvent removeDevice(DeviceId deviceId) { | 722 | public synchronized DeviceEvent removeDevice(DeviceId deviceId) { |
| 718 | - final NodeId master = mastershipService.getMasterFor(deviceId); | 723 | + final NodeId myId = clusterService.getLocalNode().id(); |
| 719 | - if (!clusterService.getLocalNode().id().equals(master)) { | 724 | + NodeId master = mastershipService.getMasterFor(deviceId); |
| 720 | - log.info("Removal of device {} requested on non master node", deviceId); | 725 | + |
| 721 | - // FIXME silently ignoring. Should be forwarding or broadcasting to | 726 | + // if there exist a master, forward |
| 722 | - // master. | 727 | + // if there is no master, try to become one and process |
| 723 | - return null; | 728 | + |
| 729 | + boolean relinquishAtEnd = false; | ||
| 730 | + if (master == null) { | ||
| 731 | + final MastershipRole myRole = mastershipService.getLocalRole(deviceId); | ||
| 732 | + if (myRole != MastershipRole.NONE) { | ||
| 733 | + relinquishAtEnd = true; | ||
| 734 | + } | ||
| 735 | + log.info("Temporarlily requesting role for {} to remove", deviceId); | ||
| 736 | + mastershipService.requestRoleFor(deviceId); | ||
| 737 | + MastershipTermService termService = mastershipService.requestTermService(); | ||
| 738 | + MastershipTerm term = termService.getMastershipTerm(deviceId); | ||
| 739 | + if (myId.equals(term.master())) { | ||
| 740 | + master = myId; | ||
| 741 | + } | ||
| 724 | } | 742 | } |
| 725 | 743 | ||
| 744 | + if (!myId.equals(master)) { | ||
| 745 | + log.info("{} has control of {}, forwarding remove request", | ||
| 746 | + master, deviceId); | ||
| 747 | + | ||
| 748 | + ClusterMessage message = new ClusterMessage( | ||
| 749 | + myId, | ||
| 750 | + DEVICE_REMOVE_REQ, | ||
| 751 | + SERIALIZER.encode(deviceId)); | ||
| 752 | + | ||
| 753 | + try { | ||
| 754 | + clusterCommunicator.unicast(message, master); | ||
| 755 | + } catch (IOException e) { | ||
| 756 | + log.error("Failed to forward {} remove request to {}", deviceId, master, e); | ||
| 757 | + } | ||
| 758 | + | ||
| 759 | + // event will be triggered after master processes it. | ||
| 760 | + return null; | ||
| 761 | + } | ||
| 762 | + | ||
| 763 | + // I have control.. | ||
| 764 | + | ||
| 726 | Timestamp timestamp = deviceClockService.getTimestamp(deviceId); | 765 | Timestamp timestamp = deviceClockService.getTimestamp(deviceId); |
| 727 | DeviceEvent event = removeDeviceInternal(deviceId, timestamp); | 766 | DeviceEvent event = removeDeviceInternal(deviceId, timestamp); |
| 728 | if (event != null) { | 767 | if (event != null) { |
| ... | @@ -735,6 +774,10 @@ public class GossipDeviceStore | ... | @@ -735,6 +774,10 @@ public class GossipDeviceStore |
| 735 | deviceId); | 774 | deviceId); |
| 736 | } | 775 | } |
| 737 | } | 776 | } |
| 777 | + if (relinquishAtEnd) { | ||
| 778 | + log.info("Relinquishing temporary role acquired for {}", deviceId); | ||
| 779 | + mastershipService.relinquishMastership(deviceId); | ||
| 780 | + } | ||
| 738 | return event; | 781 | return event; |
| 739 | } | 782 | } |
| 740 | 783 | ||
| ... | @@ -1241,6 +1284,16 @@ public class GossipDeviceStore | ... | @@ -1241,6 +1284,16 @@ public class GossipDeviceStore |
| 1241 | } | 1284 | } |
| 1242 | } | 1285 | } |
| 1243 | 1286 | ||
| 1287 | + private final class InternalRemoveRequestListener | ||
| 1288 | + implements ClusterMessageHandler { | ||
| 1289 | + @Override | ||
| 1290 | + public void handle(ClusterMessage message) { | ||
| 1291 | + log.debug("Received device remove request from peer: {}", message.sender()); | ||
| 1292 | + DeviceId did = SERIALIZER.decode(message.payload()); | ||
| 1293 | + removeDevice(did); | ||
| 1294 | + } | ||
| 1295 | + } | ||
| 1296 | + | ||
| 1244 | private class InternalDeviceRemovedEventListener implements ClusterMessageHandler { | 1297 | private class InternalDeviceRemovedEventListener implements ClusterMessageHandler { |
| 1245 | @Override | 1298 | @Override |
| 1246 | public void handle(ClusterMessage message) { | 1299 | public void handle(ClusterMessage message) { | ... | ... |
core/store/dist/src/main/java/org/onlab/onos/store/device/impl/GossipDeviceStoreMessageSubjects.java
| ... | @@ -27,6 +27,7 @@ public final class GossipDeviceStoreMessageSubjects { | ... | @@ -27,6 +27,7 @@ public final class GossipDeviceStoreMessageSubjects { |
| 27 | 27 | ||
| 28 | public static final MessageSubject DEVICE_UPDATE = new MessageSubject("peer-device-update"); | 28 | public static final MessageSubject DEVICE_UPDATE = new MessageSubject("peer-device-update"); |
| 29 | public static final MessageSubject DEVICE_OFFLINE = new MessageSubject("peer-device-offline"); | 29 | public static final MessageSubject DEVICE_OFFLINE = new MessageSubject("peer-device-offline"); |
| 30 | + public static final MessageSubject DEVICE_REMOVE_REQ = new MessageSubject("peer-device-remove-request"); | ||
| 30 | public static final MessageSubject DEVICE_REMOVED = new MessageSubject("peer-device-removed"); | 31 | public static final MessageSubject DEVICE_REMOVED = new MessageSubject("peer-device-removed"); |
| 31 | public static final MessageSubject PORT_UPDATE = new MessageSubject("peer-port-update"); | 32 | public static final MessageSubject PORT_UPDATE = new MessageSubject("peer-port-update"); |
| 32 | public static final MessageSubject PORT_STATUS_UPDATE = new MessageSubject("peer-port-status-update"); | 33 | public static final MessageSubject PORT_STATUS_UPDATE = new MessageSubject("peer-port-status-update"); | ... | ... |
| ... | @@ -361,8 +361,8 @@ | ... | @@ -361,8 +361,8 @@ |
| 361 | <!-- https://jira.codehaus.org/browse/MCOMPILER-205 --> | 361 | <!-- https://jira.codehaus.org/browse/MCOMPILER-205 --> |
| 362 | <version>2.5.1</version> | 362 | <version>2.5.1</version> |
| 363 | <configuration> | 363 | <configuration> |
| 364 | - <source>1.7</source> | 364 | + <source>1.8</source> |
| 365 | - <target>1.7</target> | 365 | + <target>1.8</target> |
| 366 | </configuration> | 366 | </configuration> |
| 367 | </plugin> | 367 | </plugin> |
| 368 | 368 | ||
| ... | @@ -407,7 +407,7 @@ | ... | @@ -407,7 +407,7 @@ |
| 407 | <plugin> | 407 | <plugin> |
| 408 | <groupId>org.apache.felix</groupId> | 408 | <groupId>org.apache.felix</groupId> |
| 409 | <artifactId>maven-scr-plugin</artifactId> | 409 | <artifactId>maven-scr-plugin</artifactId> |
| 410 | - <version>1.15.0</version> | 410 | + <version>1.20.0</version> |
| 411 | <executions> | 411 | <executions> |
| 412 | <execution> | 412 | <execution> |
| 413 | <id>generate-scr-srcdescriptor</id> | 413 | <id>generate-scr-srcdescriptor</id> | ... | ... |
| ... | @@ -3,7 +3,7 @@ | ... | @@ -3,7 +3,7 @@ |
| 3 | # Starts ONOS Apache Karaf container | 3 | # Starts ONOS Apache Karaf container |
| 4 | # ----------------------------------------------------------------------------- | 4 | # ----------------------------------------------------------------------------- |
| 5 | 5 | ||
| 6 | -export JAVA_HOME=${JAVA_HOME:-/usr/lib/jvm/java-7-openjdk-amd64/} | 6 | +#export JAVA_HOME=${JAVA_HOME:-/usr/lib/jvm/java-7-openjdk-amd64/} |
| 7 | export JAVA_OPTS="${JAVA_OPTS:--Xms256M -Xmx2048M}" | 7 | export JAVA_OPTS="${JAVA_OPTS:--Xms256M -Xmx2048M}" |
| 8 | 8 | ||
| 9 | cd /opt/onos | 9 | cd /opt/onos | ... | ... |
| ... | @@ -11,8 +11,8 @@ kill timeout 60 | ... | @@ -11,8 +11,8 @@ kill timeout 60 |
| 11 | respawn | 11 | respawn |
| 12 | 12 | ||
| 13 | env LANG=en_US.UTF-8 | 13 | env LANG=en_US.UTF-8 |
| 14 | -env JAVA_HOME=/usr/lib/jvm/java-7-openjdk-amd64 | 14 | +#env JAVA_HOME=/usr/lib/jvm/java-7-openjdk-amd64 |
| 15 | -env NEW_JAVA_HOME=/usr/lib/jvm/java-8-oracle/ | 15 | +#env NEW_JAVA_HOME=/usr/lib/jvm/java-8-oracle/ |
| 16 | 16 | ||
| 17 | pre-stop script | 17 | pre-stop script |
| 18 | /opt/onos/bin/onos halt 2>/opt/onos/var/stderr.log | 18 | /opt/onos/bin/onos halt 2>/opt/onos/var/stderr.log | ... | ... |
| ... | @@ -101,9 +101,9 @@ public class TestUtilsTest { | ... | @@ -101,9 +101,9 @@ public class TestUtilsTest { |
| 101 | @Test | 101 | @Test |
| 102 | public void testSetGetPrivateField() throws TestUtilsException { | 102 | public void testSetGetPrivateField() throws TestUtilsException { |
| 103 | 103 | ||
| 104 | - assertEquals(42, TestUtils.getField(test, "privateField")); | 104 | + assertEquals(42, (int) TestUtils.getField(test, "privateField")); |
| 105 | TestUtils.setField(test, "privateField", 0xDEAD); | 105 | TestUtils.setField(test, "privateField", 0xDEAD); |
| 106 | - assertEquals(0xDEAD, TestUtils.getField(test, "privateField")); | 106 | + assertEquals(0xDEAD, (int) TestUtils.getField(test, "privateField")); |
| 107 | } | 107 | } |
| 108 | 108 | ||
| 109 | /** | 109 | /** |
| ... | @@ -114,9 +114,9 @@ public class TestUtilsTest { | ... | @@ -114,9 +114,9 @@ public class TestUtilsTest { |
| 114 | @Test | 114 | @Test |
| 115 | public void testSetGetProtectedField() throws TestUtilsException { | 115 | public void testSetGetProtectedField() throws TestUtilsException { |
| 116 | 116 | ||
| 117 | - assertEquals(2501, TestUtils.getField(test, "protectedField")); | 117 | + assertEquals(2501, (int) TestUtils.getField(test, "protectedField")); |
| 118 | TestUtils.setField(test, "protectedField", 0xBEEF); | 118 | TestUtils.setField(test, "protectedField", 0xBEEF); |
| 119 | - assertEquals(0xBEEF, TestUtils.getField(test, "protectedField")); | 119 | + assertEquals(0xBEEF, (int) TestUtils.getField(test, "protectedField")); |
| 120 | } | 120 | } |
| 121 | 121 | ||
| 122 | /** | 122 | /** | ... | ... |
-
Please register or login to post a comment