use of org.onosproject.net.topology.TopologyEvent in project onos by opennetworkinglab.
the class TopologyEventsListCommand method doExecute.
@Override
protected void doExecute() {
TopologyMetricsService service = get(TopologyMetricsService.class);
if (outputJson()) {
print("%s", json(service.getEvents()));
} else {
for (Event event : service.getEvents()) {
print(FORMAT_EVENT, event);
if (event instanceof TopologyEvent) {
TopologyEvent topologyEvent = (TopologyEvent) event;
for (Event reason : topologyEvent.reasons()) {
print(FORMAT_REASON, reason);
}
}
// Extra empty line for clarity
print("");
}
}
}
use of org.onosproject.net.topology.TopologyEvent in project onos by opennetworkinglab.
the class DistributedTopologyStore method updateTopology.
@Override
public TopologyEvent updateTopology(ProviderId providerId, GraphDescription graphDescription, List<Event> reasons) {
// Have the default topology construct self from the description data.
DefaultTopology newTopology = new DefaultTopology(providerId, graphDescription, this::isBroadcastPoint);
updateBroadcastPoints(newTopology);
// Promote the new topology to current and return a ready-to-send event.
synchronized (this) {
// already have.
if (current != null && newTopology.time() < current.time()) {
return null;
}
current = newTopology;
return new TopologyEvent(TOPOLOGY_CHANGED, current, reasons);
}
}
use of org.onosproject.net.topology.TopologyEvent in project onos by opennetworkinglab.
the class ObjectiveTrackerTest method testEventNoReasons.
/**
* Tests an event with no associated reasons.
*
* @throws InterruptedException if the latch wait fails.
*/
@Test
public void testEventNoReasons() throws InterruptedException {
final TopologyEvent event = new TopologyEvent(TopologyEvent.Type.TOPOLOGY_CHANGED, topology, null);
listener.event(event);
assertThat(delegate.latch.await(WAIT_TIMEOUT_SECONDS, TimeUnit.SECONDS), is(true));
assertThat(delegate.intentIdsFromEvent, hasSize(0));
assertThat(delegate.compileAllFailedFromEvent, is(true));
}
use of org.onosproject.net.topology.TopologyEvent in project onos by opennetworkinglab.
the class ObjectiveTrackerTest method testEventLinkAdded.
/**
* Tests an event for a link being added.
*
* @throws InterruptedException if the latch wait fails.
*/
@Test
public void testEventLinkAdded() throws InterruptedException {
final Link link = link("src", 1, "dst", 2);
final LinkEvent linkEvent = new LinkEvent(LinkEvent.Type.LINK_ADDED, link);
reasons.add(linkEvent);
final TopologyEvent event = new TopologyEvent(TopologyEvent.Type.TOPOLOGY_CHANGED, topology, reasons);
listener.event(event);
assertThat(delegate.latch.await(WAIT_TIMEOUT_SECONDS, TimeUnit.SECONDS), is(true));
assertThat(delegate.intentIdsFromEvent, hasSize(0));
assertThat(delegate.compileAllFailedFromEvent, is(true));
}
use of org.onosproject.net.topology.TopologyEvent in project onos by opennetworkinglab.
the class TopologyEventsListCommand method json.
/**
* Produces JSON object for a topology event.
*
* @param mapper the JSON object mapper to use
* @param event the topology event with the data
* @return JSON object for the topology event
*/
private ObjectNode json(ObjectMapper mapper, Event event) {
ObjectNode result = mapper.createObjectNode();
result.put("time", event.time()).put("type", event.type().toString()).put("event", event.toString());
// Add the reasons if a TopologyEvent
if (event instanceof TopologyEvent) {
TopologyEvent topologyEvent = (TopologyEvent) event;
ArrayNode reasons = mapper.createArrayNode();
for (Event reason : topologyEvent.reasons()) {
reasons.add(json(mapper, reason));
}
result.set("reasons", reasons);
}
return result;
}
Aggregations