Sho SHIMIZU
Committed by Gerrit Code Review

Ignore config event if not master not to cause concurrent registrations

Change-Id: I1455ad9bbf373cd3b5742d35b8edb7392c4ca9d7
...@@ -23,6 +23,7 @@ import java.util.Set; ...@@ -23,6 +23,7 @@ import java.util.Set;
23 import java.util.concurrent.ExecutorService; 23 import java.util.concurrent.ExecutorService;
24 24
25 import org.onlab.util.Bandwidth; 25 import org.onlab.util.Bandwidth;
26 +import org.onosproject.mastership.MastershipService;
26 import org.onosproject.net.ConnectPoint; 27 import org.onosproject.net.ConnectPoint;
27 import org.onosproject.net.config.NetworkConfigEvent; 28 import org.onosproject.net.config.NetworkConfigEvent;
28 import org.onosproject.net.config.NetworkConfigListener; 29 import org.onosproject.net.config.NetworkConfigListener;
...@@ -51,6 +52,7 @@ final class ResourceNetworkConfigListener implements NetworkConfigListener { ...@@ -51,6 +52,7 @@ final class ResourceNetworkConfigListener implements NetworkConfigListener {
51 52
52 private final ResourceAdminService adminService; 53 private final ResourceAdminService adminService;
53 private final NetworkConfigService cfgService; 54 private final NetworkConfigService cfgService;
55 + private final MastershipService mastershipService;
54 private final ExecutorService executor; 56 private final ExecutorService executor;
55 57
56 /** 58 /**
...@@ -61,9 +63,10 @@ final class ResourceNetworkConfigListener implements NetworkConfigListener { ...@@ -61,9 +63,10 @@ final class ResourceNetworkConfigListener implements NetworkConfigListener {
61 * @param executor Executor to use. 63 * @param executor Executor to use.
62 */ 64 */
63 ResourceNetworkConfigListener(ResourceAdminService adminService, NetworkConfigService cfgService, 65 ResourceNetworkConfigListener(ResourceAdminService adminService, NetworkConfigService cfgService,
64 - ExecutorService executor) { 66 + MastershipService mastershipService, ExecutorService executor) {
65 this.adminService = checkNotNull(adminService); 67 this.adminService = checkNotNull(adminService);
66 this.cfgService = checkNotNull(cfgService); 68 this.cfgService = checkNotNull(cfgService);
69 + this.mastershipService = checkNotNull(mastershipService);
67 this.executor = checkNotNull(executor); 70 this.executor = checkNotNull(executor);
68 } 71 }
69 72
...@@ -99,6 +102,10 @@ final class ResourceNetworkConfigListener implements NetworkConfigListener { ...@@ -99,6 +102,10 @@ final class ResourceNetworkConfigListener implements NetworkConfigListener {
99 checkArgument(event.configClass() == BandwidthCapacity.class); 102 checkArgument(event.configClass() == BandwidthCapacity.class);
100 103
101 ConnectPoint cp = (ConnectPoint) event.subject(); 104 ConnectPoint cp = (ConnectPoint) event.subject();
105 + if (!mastershipService.isLocalMaster(cp.deviceId())) {
106 + return;
107 + }
108 +
102 BandwidthCapacity bwCapacity = cfgService.getConfig(cp, BandwidthCapacity.class); 109 BandwidthCapacity bwCapacity = cfgService.getConfig(cp, BandwidthCapacity.class);
103 110
104 switch (event.type()) { 111 switch (event.type()) {
......
...@@ -92,7 +92,7 @@ public final class ResourceRegistrar { ...@@ -92,7 +92,7 @@ public final class ResourceRegistrar {
92 public void activate() { 92 public void activate() {
93 factories.forEach(cfgRegistry::registerConfigFactory); 93 factories.forEach(cfgRegistry::registerConfigFactory);
94 94
95 - cfgListener = new ResourceNetworkConfigListener(adminService, cfgRegistry, executor); 95 + cfgListener = new ResourceNetworkConfigListener(adminService, cfgRegistry, mastershipService, executor);
96 cfgRegistry.addListener(cfgListener); 96 cfgRegistry.addListener(cfgListener);
97 97
98 deviceListener = new ResourceDeviceListener(adminService, resourceService, 98 deviceListener = new ResourceDeviceListener(adminService, resourceService,
......