use of org.onosproject.cluster.ClusterEvent 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.cluster.ClusterEvent 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.cluster.ClusterEvent in project onos by opennetworkinglab.
the class TopologyViewMessageHandler method sendAllInstances.
// Sends all controller nodes to the client as node-added messages.
private void sendAllInstances(String messageType) {
List<ControllerNode> nodes = new ArrayList<>(services.cluster().getNodes());
nodes.sort(NODE_COMPARATOR);
for (ControllerNode node : nodes) {
sendMessage(instanceMessage(new ClusterEvent(INSTANCE_ADDED, node), messageType));
}
}
use of org.onosproject.cluster.ClusterEvent in project onos by opennetworkinglab.
the class UpgradeManager method handleClusterEvent.
/**
* Handles a cluster event.
*
* @param event the cluster event
*/
protected void handleClusterEvent(ClusterEvent event) {
checkPermission(CLUSTER_EVENT);
// If an instance was deactivated, check whether we need to roll back the upgrade.
if (event.type() == ClusterEvent.Type.INSTANCE_DEACTIVATED) {
Upgrade upgrade = getState();
if (upgrade.status().upgraded()) {
// Get the upgraded subset of the cluster and check whether the down node is a member
// of the upgraded subset. If so, roll back the upgrade to tolerate the failure.
Set<NodeId> upgradedNodes = clusterService.getNodes().stream().map(ControllerNode::id).filter(id -> clusterService.getVersion(id).equals(upgrade.target())).collect(Collectors.toSet());
if (upgradedNodes.contains(event.subject().id())) {
log.warn("Upgrade failure detected: rolling back upgrade");
rollback();
}
}
}
}
use of org.onosproject.cluster.ClusterEvent in project onos by opennetworkinglab.
the class UpgradeManagerTest method testCrashRollback.
@Test
public void testCrashRollback() throws Exception {
UpgradeManager upgradeManager = createUpgradeManager(Version.version("1.0.0"), new Upgrade(Version.version("1.0.0"), Version.version("1.0.1"), Upgrade.Status.UPGRADED), Arrays.asList(Version.version("1.0.0"), Version.version("1.0.0"), Version.version("1.0.1")));
assertFalse(upgradeManager.isLocalActive());
upgradeManager.handleClusterEvent(new ClusterEvent(ClusterEvent.Type.INSTANCE_DEACTIVATED, upgradeManager.clusterService.getNode(NodeId.nodeId("2"))));
assertEquals(Upgrade.Status.ROLLED_BACK, upgradeManager.getState().status());
assertTrue(upgradeManager.isLocalActive());
assertFalse(upgradeManager.isLocalUpgraded());
}
Aggregations