Yuta HIGUCHI

Mastership related minor fixes on DeviceManager

Change-Id: I8aefedd22b285f132d8b0cd2e7b76bf422dcf444
...@@ -153,8 +153,11 @@ public class DeviceManager ...@@ -153,8 +153,11 @@ public class DeviceManager
153 DeviceProvider provider = getProvider(device.providerId()); 153 DeviceProvider provider = getProvider(device.providerId());
154 if (provider != null) { 154 if (provider != null) {
155 provider.roleChanged(device, newRole); 155 provider.roleChanged(device, newRole);
156 +
157 + // only trigger event when request was sent to provider
158 + // TODO: consider removing this from Device event type?
159 + post(new DeviceEvent(DEVICE_MASTERSHIP_CHANGED, device));
156 } 160 }
157 - post(new DeviceEvent(DEVICE_MASTERSHIP_CHANGED, device));
158 } 161 }
159 } 162 }
160 163
...@@ -164,6 +167,7 @@ public class DeviceManager ...@@ -164,6 +167,7 @@ public class DeviceManager
164 // XXX is this intended to apply to the full global topology? 167 // XXX is this intended to apply to the full global topology?
165 // if so, we probably don't want the fact that we aren't 168 // if so, we probably don't want the fact that we aren't
166 // MASTER to get in the way, as it would do now. 169 // MASTER to get in the way, as it would do now.
170 + // FIXME: forward or broadcast and let the Master handler the event.
167 DeviceEvent event = store.removeDevice(deviceId); 171 DeviceEvent event = store.removeDevice(deviceId);
168 if (event != null) { 172 if (event != null) {
169 log.info("Device {} administratively removed", deviceId); 173 log.info("Device {} administratively removed", deviceId);
...@@ -347,6 +351,9 @@ public class DeviceManager ...@@ -347,6 +351,9 @@ public class DeviceManager
347 deviceId); 351 deviceId);
348 if (role == MastershipRole.MASTER) { 352 if (role == MastershipRole.MASTER) {
349 mastershipService.relinquishMastership(deviceId); 353 mastershipService.relinquishMastership(deviceId);
354 + // TODO: Shouldn't we be triggering event?
355 + //final Device device = getDevice(deviceId);
356 + //post(new DeviceEvent(DEVICE_MASTERSHIP_CHANGED, device));
350 } 357 }
351 } 358 }
352 } 359 }
...@@ -367,7 +374,7 @@ public class DeviceManager ...@@ -367,7 +374,7 @@ public class DeviceManager
367 final NodeId myNodeId = clusterService.getLocalNode().id(); 374 final NodeId myNodeId = clusterService.getLocalNode().id();
368 375
369 log.info("## got Mastershipevent for dev {}", did); 376 log.info("## got Mastershipevent for dev {}", did);
370 - if (myNodeId.equals(event.node())) { 377 + if (myNodeId.equals(event.roleInfo().master())) {
371 MastershipTerm term = termService.getMastershipTerm(did); 378 MastershipTerm term = termService.getMastershipTerm(did);
372 379
373 if (!myNodeId.equals(term.master())) { 380 if (!myNodeId.equals(term.master())) {
...@@ -398,7 +405,7 @@ public class DeviceManager ...@@ -398,7 +405,7 @@ public class DeviceManager
398 } 405 }
399 //TODO re-collect device information to fix potential staleness 406 //TODO re-collect device information to fix potential staleness
400 applyRole(did, MastershipRole.MASTER); 407 applyRole(did, MastershipRole.MASTER);
401 - } else { 408 + } else if (event.roleInfo().backups().contains(myNodeId)) {
402 applyRole(did, MastershipRole.STANDBY); 409 applyRole(did, MastershipRole.STANDBY);
403 } 410 }
404 } 411 }
......