Yuta HIGUCHI

Device Mastership

try to fix Masteship recognition mismatch when MastershipEvent suggest different view.

Change-Id: If1aba3d330978c48e8c4053fb47f4d149d57966e
...@@ -452,6 +452,35 @@ public class DeviceManager ...@@ -452,6 +452,35 @@ public class DeviceManager
452 return; 452 return;
453 } 453 }
454 applyRole(did, MastershipRole.STANDBY); 454 applyRole(did, MastershipRole.STANDBY);
455 + } else {
456 + // Event suggests that this Node has no connection to this Device
457 + // confirm.
458 + final Device device = getDevice(did);
459 + if (!isReachable(device)) {
460 + // not connection to device, as expected
461 + return;
462 + }
463 + // connection seems to exist
464 + log.info("Detected mastership info mismatch, requesting Role");
465 + mastershipService.requestRoleFor(did);
466 + final MastershipTerm term = termService.getMastershipTerm(did);
467 + if (myNodeId.equals(term.master())) {
468 + // became MASTER
469 + // TODO: consider slicing out method for applying MASTER role
470 + deviceClockProviderService.setMastershipTerm(did, term);
471 +
472 + //flag the device as online. Is there a better way to do this?
473 + DeviceEvent devEvent =
474 + store.createOrUpdateDevice(device.providerId(), did,
475 + new DefaultDeviceDescription(
476 + did.uri(), device.type(), device.manufacturer(),
477 + device.hwVersion(), device.swVersion(),
478 + device.serialNumber(), device.chassisId()));
479 + applyRole(did, MastershipRole.MASTER);
480 + post(devEvent);
481 + } else {
482 + applyRole(did, MastershipRole.STANDBY);
483 + }
455 } 484 }
456 } 485 }
457 486
......