use of org.onosproject.net.MastershipRole in project onos by opennetworkinglab.
the class ECDeviceStore method removeDevice.
@Override
public DeviceEvent removeDevice(DeviceId deviceId) {
NodeId master = mastershipService.getMasterFor(deviceId);
// if there exist a master, forward
// if there is no master, try to become one and process
boolean relinquishAtEnd = false;
if (master == null) {
final MastershipRole myRole = mastershipService.getLocalRole(deviceId);
if (myRole != MastershipRole.NONE) {
relinquishAtEnd = true;
}
log.debug("Temporarily requesting role for {} to remove", deviceId);
MastershipRole role = Futures.getUnchecked(mastershipService.requestRoleFor(deviceId));
if (role == MastershipRole.MASTER) {
master = localNodeId;
}
}
if (!localNodeId.equals(master)) {
log.debug("{} has control of {}, forwarding remove request", master, deviceId);
clusterCommunicator.unicast(deviceId, DEVICE_REMOVE_REQ, SERIALIZER::encode, master).whenComplete((r, e) -> {
if (e != null) {
log.error("Failed to forward {} remove request to its master", deviceId, e);
}
});
return null;
}
// I have control..
DeviceEvent event = null;
final DeviceKey deviceKey = new DeviceKey(getPrimaryProviderId(deviceId), deviceId);
DeviceDescription removedDeviceDescription = deviceDescriptions.remove(deviceKey);
if (removedDeviceDescription != null) {
event = purgeDeviceCache(deviceId);
}
if (relinquishAtEnd) {
log.debug("Relinquishing temporary role acquired for {}", deviceId);
mastershipService.relinquishMastership(deviceId);
}
return event;
}
use of org.onosproject.net.MastershipRole 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);
}
}
}
use of org.onosproject.net.MastershipRole in project onos by opennetworkinglab.
the class SimpleVirtualMastershipStore method getMastership.
@Override
public MastershipInfo getMastership(NetworkId networkId, DeviceId deviceId) {
Map<DeviceId, NodeId> masterMap = getMasterMap(networkId);
Map<DeviceId, AtomicInteger> termMap = getTermMap(networkId);
Map<DeviceId, List<NodeId>> backups = getBackups(networkId);
ImmutableMap.Builder<NodeId, MastershipRole> roleBuilder = ImmutableMap.builder();
NodeId master = masterMap.get(deviceId);
if (master != null) {
roleBuilder.put(master, MastershipRole.MASTER);
}
backups.getOrDefault(deviceId, Collections.emptyList()).forEach(nodeId -> roleBuilder.put(nodeId, MastershipRole.STANDBY));
clusterService.getNodes().stream().filter(node -> !masterMap.containsValue(node.id())).filter(node -> !backups.get(deviceId).contains(node.id())).forEach(node -> roleBuilder.put(node.id(), MastershipRole.NONE));
return new MastershipInfo(termMap.getOrDefault(deviceId, new AtomicInteger(NOTHING)).get(), Optional.ofNullable(master), roleBuilder.build());
}
use of org.onosproject.net.MastershipRole in project onos by opennetworkinglab.
the class SimpleMastershipStore method getMastership.
@Override
public MastershipInfo getMastership(DeviceId deviceId) {
ImmutableMap.Builder<NodeId, MastershipRole> roleBuilder = ImmutableMap.builder();
NodeId master = masterMap.get(deviceId);
if (master != null) {
roleBuilder.put(master, MastershipRole.MASTER);
}
backups.getOrDefault(deviceId, Collections.emptyList()).forEach(nodeId -> roleBuilder.put(nodeId, MastershipRole.STANDBY));
return new MastershipInfo(termMap.getOrDefault(deviceId, new AtomicInteger(NOTHING)).get(), Optional.ofNullable(master), roleBuilder.build());
}
use of org.onosproject.net.MastershipRole in project onos by opennetworkinglab.
the class SimpleMastershipStore method getRole.
@Override
public MastershipRole getRole(NodeId nodeId, DeviceId deviceId) {
// just query
NodeId current = masterMap.get(deviceId);
MastershipRole role;
if (current != null && current.equals(nodeId)) {
return MastershipRole.MASTER;
}
if (backups.getOrDefault(deviceId, Collections.emptyList()).contains(nodeId)) {
role = MastershipRole.STANDBY;
} else {
role = MastershipRole.NONE;
}
return role;
}
Aggregations