use of org.onosproject.mastership.MastershipEvent in project onos by opennetworkinglab.
the class EventsCommand method printEvent.
private void printEvent(Event<?, ?> event) {
if (event instanceof DeviceEvent) {
DeviceEvent deviceEvent = (DeviceEvent) event;
if (event.type().toString().startsWith("PORT")) {
// Port event
print("%s %s\t%s/%s [%s]", Tools.defaultOffsetDataTime(event.time()), event.type(), deviceEvent.subject().id(), deviceEvent.port().number(), deviceEvent.port());
} else {
// Device event
print("%s %s\t%s [%s]", Tools.defaultOffsetDataTime(event.time()), event.type(), deviceEvent.subject().id(), deviceEvent.subject());
}
} else if (event instanceof MastershipEvent) {
print("%s %s\t%s [%s]", Tools.defaultOffsetDataTime(event.time()), event.type(), event.subject(), ((MastershipEvent) event).roleInfo());
} else if (event instanceof LinkEvent) {
LinkEvent linkEvent = (LinkEvent) event;
Link link = linkEvent.subject();
print("%s %s\t%s/%s-%s/%s [%s]", Tools.defaultOffsetDataTime(event.time()), event.type(), link.src().deviceId(), link.src().port(), link.dst().deviceId(), link.dst().port(), link);
} else if (event instanceof HostEvent) {
HostEvent hostEvent = (HostEvent) event;
print("%s %s\t%s [%s->%s]", Tools.defaultOffsetDataTime(event.time()), event.type(), hostEvent.subject().id(), hostEvent.prevSubject(), hostEvent.subject());
} else if (event instanceof TopologyEvent) {
TopologyEvent topoEvent = (TopologyEvent) event;
List<Event> reasons = MoreObjects.firstNonNull(topoEvent.reasons(), ImmutableList.<Event>of());
Topology topo = topoEvent.subject();
String summary = String.format("(d=%d,l=%d,c=%d)", topo.deviceCount(), topo.linkCount(), topo.clusterCount());
print("%s %s%s [%s]", Tools.defaultOffsetDataTime(event.time()), event.type(), summary, reasons.stream().map(e -> e.type()).collect(toList()));
} else if (event instanceof ClusterEvent) {
print("%s %s\t%s [%s]", Tools.defaultOffsetDataTime(event.time()), event.type(), ((ClusterEvent) event).subject().id(), event.subject());
} else {
// Unknown Event?
print("%s %s\t%s [%s]", Tools.defaultOffsetDataTime(event.time()), event.type(), event.subject(), event);
}
}
use of org.onosproject.mastership.MastershipEvent in project onos by opennetworkinglab.
the class EventsCommand method doExecute.
@Override
protected void doExecute() {
EventHistoryService eventHistoryService = get(EventHistoryService.class);
Stream<Event<?, ?>> events = eventHistoryService.history().stream();
boolean dumpAll = all || !(mastership || device || link || topology || host || cluster || intent);
if (!dumpAll) {
Predicate<Event<?, ?>> filter = (defaultIs) -> false;
if (mastership) {
filter = filter.or(evt -> evt instanceof MastershipEvent);
}
if (device) {
filter = filter.or(evt -> evt instanceof DeviceEvent);
}
if (link) {
filter = filter.or(evt -> evt instanceof LinkEvent);
}
if (topology) {
filter = filter.or(evt -> evt instanceof TopologyEvent);
}
if (host) {
filter = filter.or(evt -> evt instanceof HostEvent);
}
if (cluster) {
filter = filter.or(evt -> evt instanceof ClusterEvent);
}
if (intent) {
filter = filter.or(evt -> evt instanceof IntentEvent);
}
events = events.filter(filter);
}
if (maxSize > 0) {
events = events.limit(maxSize);
}
if (outputJson()) {
ArrayNode jsonEvents = events.map(this::json).collect(toArrayNode());
printJson(jsonEvents);
} else {
events.forEach(this::printEvent);
}
}
use of org.onosproject.mastership.MastershipEvent in project onos by opennetworkinglab.
the class ConsistentVirtualDeviceMastershipStore method relinquishLocalRoleByNetwork.
private CompletableFuture<MastershipEvent> relinquishLocalRoleByNetwork(NetworkId networkId, DeviceId deviceId) {
checkArgument(networkId != null, NETWORK_ID_NULL);
checkArgument(deviceId != null, DEVICE_ID_NULL);
String leadershipTopic = createDeviceMastershipTopic(networkId, deviceId);
if (!leadershipService.getCandidates(leadershipTopic).contains(localNodeId)) {
return CompletableFuture.completedFuture(null);
}
MastershipEvent.Type eventType = localNodeId.equals(leadershipService.getLeader(leadershipTopic)) ? MastershipEvent.Type.MASTER_CHANGED : MastershipEvent.Type.BACKUPS_CHANGED;
leadershipService.withdraw(leadershipTopic);
return CompletableFuture.completedFuture(new MastershipEvent(eventType, deviceId, getMastership(networkId, deviceId)));
}
use of org.onosproject.mastership.MastershipEvent in project onos by opennetworkinglab.
the class SimpleVirtualMastershipStore method requestRole.
@Override
public CompletableFuture<MastershipRole> requestRole(NetworkId networkId, DeviceId deviceId) {
// query+possible reelection
NodeId node = clusterService.getLocalNode().id();
MastershipRole role = getRole(networkId, node, deviceId);
Map<DeviceId, NodeId> masterMap = getMasterMap(networkId);
switch(role) {
case MASTER:
return CompletableFuture.completedFuture(MastershipRole.MASTER);
case STANDBY:
if (getMaster(networkId, deviceId) == null) {
// no master => become master
masterMap.put(deviceId, node);
incrementTerm(networkId, deviceId);
// remove from backup list
removeFromBackups(networkId, deviceId, node);
notifyDelegate(networkId, new MastershipEvent(MASTER_CHANGED, deviceId, getMastership(networkId, deviceId)));
return CompletableFuture.completedFuture(MastershipRole.MASTER);
}
return CompletableFuture.completedFuture(MastershipRole.STANDBY);
case NONE:
if (getMaster(networkId, deviceId) == null) {
// no master => become master
masterMap.put(deviceId, node);
incrementTerm(networkId, deviceId);
notifyDelegate(networkId, new MastershipEvent(MASTER_CHANGED, deviceId, getMastership(networkId, deviceId)));
return CompletableFuture.completedFuture(MastershipRole.MASTER);
}
// add to backup list
if (addToBackup(networkId, deviceId, node)) {
notifyDelegate(networkId, new MastershipEvent(BACKUPS_CHANGED, deviceId, getMastership(networkId, deviceId)));
}
return CompletableFuture.completedFuture(MastershipRole.STANDBY);
default:
log.warn("unknown Mastership Role {}", role);
}
return CompletableFuture.completedFuture(role);
}
use of org.onosproject.mastership.MastershipEvent in project onos by opennetworkinglab.
the class SimpleVirtualMastershipStore method relinquishRole.
@Override
public synchronized CompletableFuture<MastershipEvent> relinquishRole(NetworkId networkId, NodeId nodeId, DeviceId deviceId) {
Map<DeviceId, NodeId> masterMap = getMasterMap(networkId);
MastershipRole role = getRole(networkId, nodeId, deviceId);
switch(role) {
case MASTER:
NodeId backup = reelect(networkId, deviceId, nodeId);
masterMap.put(deviceId, backup);
incrementTerm(networkId, deviceId);
return CompletableFuture.completedFuture(new MastershipEvent(MASTER_CHANGED, deviceId, getMastership(networkId, deviceId)));
case STANDBY:
if (removeFromBackups(networkId, deviceId, nodeId)) {
return CompletableFuture.completedFuture(new MastershipEvent(BACKUPS_CHANGED, deviceId, getMastership(networkId, deviceId)));
}
break;
case NONE:
break;
default:
log.warn("unknown Mastership Role {}", role);
}
return CompletableFuture.completedFuture(null);
}
Aggregations