use of org.onosproject.net.MastershipRole.NONE in project onos by opennetworkinglab.
the class DeviceManager method mastershipCheck.
/**
* Checks if all the reachable devices have a valid mastership role.
*/
private void mastershipCheck() {
log.debug("Checking mastership");
for (Device device : getDevices()) {
final DeviceId deviceId = device.id();
MastershipRole myRole = mastershipService.getLocalRole(deviceId);
log.trace("Checking device {}. Current role is {}", deviceId, myRole);
log.debug("Device {} local status is {}", deviceId, localStatus(deviceId));
final boolean isGracePeriodOn = inGracePeriod(deviceId);
final boolean isReachable = isReachable(deviceId, isGracePeriodOn);
// Passed the grace period and it is still not reachable
if (!isGracePeriodOn && !isReachable) {
if (myRole != NONE) {
// Verify if the device is fully disconnected from the cluster
if (updateMastershipFor(deviceId) == null && myRole == MASTER && isAvailable(deviceId)) {
log.info("Local Role {}, Marking unreachable device {} offline", MASTER, deviceId);
// Following the deviceDisconnected method logic (line 734) we are marking also all the
// ports as disabled.
List<PortDescription> descs = store.getPortDescriptions(getProvider(deviceId).id(), deviceId).map(desc -> ensurePortEnabledState(desc, false)).collect(Collectors.toList());
store.updatePorts(getProvider(deviceId).id(), deviceId, descs);
post(store.markOffline(deviceId));
}
} else {
// never be hit unless in a device removed phase for NONE mastership roles.
try {
mastershipService.requestRoleFor(deviceId).get();
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
log.error("Interrupted waiting for Mastership", e);
} catch (ExecutionException e) {
log.error("Encountered an error waiting for Mastership", e);
}
MastershipTerm term = termService.getMastershipTerm(deviceId);
if (updateMastershipFor(deviceId) == null && term != null && localNodeId.equals(term.master()) && isAvailable(deviceId)) {
log.info("Marking unreachable device {} offline", deviceId);
// Following the deviceDisconnected method logic (line 734) we are marking also all the
// ports as disabled.
List<PortDescription> descs = store.getPortDescriptions(getProvider(deviceId).id(), deviceId).map(desc -> ensurePortEnabledState(desc, false)).collect(Collectors.toList());
store.updatePorts(getProvider(deviceId).id(), deviceId, descs);
post(store.markOffline(deviceId));
}
}
roleToAcknowledge.remove(deviceId);
} else if (isReachable) {
// If this node is the master, ensure the device is marked online.
if (myRole == MASTER && canMarkOnline(device)) {
log.debug("Can mark online {}", deviceId);
post(store.markOnline(deviceId));
}
log.debug("{} is reachable - reasserting the role", deviceId);
// Device is still reachable. It is useful for some protocols
// to reassert the role. Note: NONE triggers request to MastershipService
reassertRole(deviceId, myRole);
} else {
// Do not proceed furthermore if the grace period is still on
log.debug("Skipping mastership check for {}", deviceId);
}
}
}
Aggregations