Ignore device event if not master not to cause concurrent registrations
This patch resolves ONOS-4032 Change-Id: I12e2ed7d352928fe94559ab978f5db7e9f56f1b0
Showing
2 changed files
with
17 additions
and
3 deletions
| ... | @@ -21,6 +21,7 @@ import org.onlab.packet.MplsLabel; | ... | @@ -21,6 +21,7 @@ import org.onlab.packet.MplsLabel; |
| 21 | import org.onlab.packet.VlanId; | 21 | import org.onlab.packet.VlanId; |
| 22 | import org.onlab.util.Bandwidth; | 22 | import org.onlab.util.Bandwidth; |
| 23 | import org.onlab.util.ItemNotFoundException; | 23 | import org.onlab.util.ItemNotFoundException; |
| 24 | +import org.onosproject.mastership.MastershipService; | ||
| 24 | import org.onosproject.net.ConnectPoint; | 25 | import org.onosproject.net.ConnectPoint; |
| 25 | import org.onosproject.net.Device; | 26 | import org.onosproject.net.Device; |
| 26 | import org.onosproject.net.DeviceId; | 27 | import org.onosproject.net.DeviceId; |
| ... | @@ -67,6 +68,7 @@ final class ResourceDeviceListener implements DeviceListener { | ... | @@ -67,6 +68,7 @@ final class ResourceDeviceListener implements DeviceListener { |
| 67 | private final ResourceAdminService adminService; | 68 | private final ResourceAdminService adminService; |
| 68 | private final ResourceService resourceService; | 69 | private final ResourceService resourceService; |
| 69 | private final DeviceService deviceService; | 70 | private final DeviceService deviceService; |
| 71 | + private final MastershipService mastershipService; | ||
| 70 | private final DriverService driverService; | 72 | private final DriverService driverService; |
| 71 | private final NetworkConfigService netcfgService; | 73 | private final NetworkConfigService netcfgService; |
| 72 | private final ExecutorService executor; | 74 | private final ExecutorService executor; |
| ... | @@ -78,16 +80,19 @@ final class ResourceDeviceListener implements DeviceListener { | ... | @@ -78,16 +80,19 @@ final class ResourceDeviceListener implements DeviceListener { |
| 78 | * @param adminService instance invoked to register resources | 80 | * @param adminService instance invoked to register resources |
| 79 | * @param resourceService {@link ResourceService} to be used | 81 | * @param resourceService {@link ResourceService} to be used |
| 80 | * @param deviceService {@link DeviceService} to be used | 82 | * @param deviceService {@link DeviceService} to be used |
| 83 | + * @param mastershipService {@link MastershipService} to be used | ||
| 81 | * @param driverService {@link DriverService} to be used | 84 | * @param driverService {@link DriverService} to be used |
| 82 | * @param netcfgService {@link NetworkConfigService} to be used. | 85 | * @param netcfgService {@link NetworkConfigService} to be used. |
| 83 | * @param executor executor used for processing resource registration | 86 | * @param executor executor used for processing resource registration |
| 84 | */ | 87 | */ |
| 85 | ResourceDeviceListener(ResourceAdminService adminService, ResourceService resourceService, | 88 | ResourceDeviceListener(ResourceAdminService adminService, ResourceService resourceService, |
| 86 | - DeviceService deviceService, DriverService driverService, | 89 | + DeviceService deviceService, MastershipService mastershipService, |
| 87 | - NetworkConfigService netcfgService, ExecutorService executor) { | 90 | + DriverService driverService, NetworkConfigService netcfgService, |
| 91 | + ExecutorService executor) { | ||
| 88 | this.adminService = checkNotNull(adminService); | 92 | this.adminService = checkNotNull(adminService); |
| 89 | this.resourceService = checkNotNull(resourceService); | 93 | this.resourceService = checkNotNull(resourceService); |
| 90 | this.deviceService = checkNotNull(deviceService); | 94 | this.deviceService = checkNotNull(deviceService); |
| 95 | + this.mastershipService = checkNotNull(mastershipService); | ||
| 91 | this.driverService = checkNotNull(driverService); | 96 | this.driverService = checkNotNull(driverService); |
| 92 | this.netcfgService = checkNotNull(netcfgService); | 97 | this.netcfgService = checkNotNull(netcfgService); |
| 93 | this.executor = checkNotNull(executor); | 98 | this.executor = checkNotNull(executor); |
| ... | @@ -96,6 +101,11 @@ final class ResourceDeviceListener implements DeviceListener { | ... | @@ -96,6 +101,11 @@ final class ResourceDeviceListener implements DeviceListener { |
| 96 | @Override | 101 | @Override |
| 97 | public void event(DeviceEvent event) { | 102 | public void event(DeviceEvent event) { |
| 98 | Device device = event.subject(); | 103 | Device device = event.subject(); |
| 104 | + // registration happens only when the caller is the master of the device | ||
| 105 | + if (!mastershipService.isLocalMaster(device.id())) { | ||
| 106 | + return; | ||
| 107 | + } | ||
| 108 | + | ||
| 99 | switch (event.type()) { | 109 | switch (event.type()) { |
| 100 | case DEVICE_ADDED: | 110 | case DEVICE_ADDED: |
| 101 | registerDeviceResource(device); | 111 | registerDeviceResource(device); | ... | ... |
| ... | @@ -23,6 +23,7 @@ import org.apache.felix.scr.annotations.Component; | ... | @@ -23,6 +23,7 @@ import org.apache.felix.scr.annotations.Component; |
| 23 | import org.apache.felix.scr.annotations.Deactivate; | 23 | import org.apache.felix.scr.annotations.Deactivate; |
| 24 | import org.apache.felix.scr.annotations.Reference; | 24 | import org.apache.felix.scr.annotations.Reference; |
| 25 | import org.apache.felix.scr.annotations.ReferenceCardinality; | 25 | import org.apache.felix.scr.annotations.ReferenceCardinality; |
| 26 | +import org.onosproject.mastership.MastershipService; | ||
| 26 | import org.onosproject.net.ConnectPoint; | 27 | import org.onosproject.net.ConnectPoint; |
| 27 | import org.onosproject.net.config.ConfigFactory; | 28 | import org.onosproject.net.config.ConfigFactory; |
| 28 | import org.onosproject.net.config.NetworkConfigListener; | 29 | import org.onosproject.net.config.NetworkConfigListener; |
| ... | @@ -63,6 +64,9 @@ public final class ResourceRegistrar { | ... | @@ -63,6 +64,9 @@ public final class ResourceRegistrar { |
| 63 | protected DeviceService deviceService; | 64 | protected DeviceService deviceService; |
| 64 | 65 | ||
| 65 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) | 66 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
| 67 | + protected MastershipService mastershipService; | ||
| 68 | + | ||
| 69 | + @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) | ||
| 66 | protected NetworkConfigRegistry cfgRegistry; | 70 | protected NetworkConfigRegistry cfgRegistry; |
| 67 | 71 | ||
| 68 | private final Logger log = getLogger(getClass()); | 72 | private final Logger log = getLogger(getClass()); |
| ... | @@ -92,7 +96,7 @@ public final class ResourceRegistrar { | ... | @@ -92,7 +96,7 @@ public final class ResourceRegistrar { |
| 92 | cfgRegistry.addListener(cfgListener); | 96 | cfgRegistry.addListener(cfgListener); |
| 93 | 97 | ||
| 94 | deviceListener = new ResourceDeviceListener(adminService, resourceService, | 98 | deviceListener = new ResourceDeviceListener(adminService, resourceService, |
| 95 | - deviceService, driverService, cfgRegistry, executor); | 99 | + deviceService, mastershipService, driverService, cfgRegistry, executor); |
| 96 | deviceService.addListener(deviceListener); | 100 | deviceService.addListener(deviceListener); |
| 97 | 101 | ||
| 98 | // TODO Attempt initial registration of existing resources? | 102 | // TODO Attempt initial registration of existing resources? | ... | ... |
-
Please register or login to post a comment