Search in sources :

Example 1 with ClusterEvent

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);
    }
}
Also used : DeviceEvent(org.onosproject.net.device.DeviceEvent) HostEvent(org.onosproject.net.host.HostEvent) ClusterEvent(org.onosproject.cluster.ClusterEvent) LinkEvent(org.onosproject.net.link.LinkEvent) MastershipEvent(org.onosproject.mastership.MastershipEvent) TopologyEvent(org.onosproject.net.topology.TopologyEvent) IntentEvent(org.onosproject.net.intent.IntentEvent) LinkEvent(org.onosproject.net.link.LinkEvent) MastershipEvent(org.onosproject.mastership.MastershipEvent) HostEvent(org.onosproject.net.host.HostEvent) Event(org.onosproject.event.Event) TopologyEvent(org.onosproject.net.topology.TopologyEvent) ClusterEvent(org.onosproject.cluster.ClusterEvent) DeviceEvent(org.onosproject.net.device.DeviceEvent) Topology(org.onosproject.net.topology.Topology) Link(org.onosproject.net.Link)

Example 2 with ClusterEvent

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);
    }
}
Also used : Tools(org.onlab.util.Tools) IntentEvent(org.onosproject.net.intent.IntentEvent) LinkEvent(org.onosproject.net.link.LinkEvent) Link(org.onosproject.net.Link) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) Command(org.apache.karaf.shell.api.action.Command) MastershipEvent(org.onosproject.mastership.MastershipEvent) Topology(org.onosproject.net.topology.Topology) ImmutableList(com.google.common.collect.ImmutableList) HostEvent(org.onosproject.net.host.HostEvent) JsonNode(com.fasterxml.jackson.databind.JsonNode) Collector(java.util.stream.Collector) Event(org.onosproject.event.Event) PrintWriter(java.io.PrintWriter) TopologyEvent(org.onosproject.net.topology.TopologyEvent) ClusterEvent(org.onosproject.cluster.ClusterEvent) Predicate(java.util.function.Predicate) StringWriter(java.io.StringWriter) MoreObjects(com.google.common.base.MoreObjects) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode) AbstractShellCommand(org.onosproject.cli.AbstractShellCommand) List(java.util.List) Collectors.toList(java.util.stream.Collectors.toList) Stream(java.util.stream.Stream) Service(org.apache.karaf.shell.api.action.lifecycle.Service) DeviceEvent(org.onosproject.net.device.DeviceEvent) Option(org.apache.karaf.shell.api.action.Option) DeviceEvent(org.onosproject.net.device.DeviceEvent) MastershipEvent(org.onosproject.mastership.MastershipEvent) TopologyEvent(org.onosproject.net.topology.TopologyEvent) HostEvent(org.onosproject.net.host.HostEvent) ClusterEvent(org.onosproject.cluster.ClusterEvent) LinkEvent(org.onosproject.net.link.LinkEvent) IntentEvent(org.onosproject.net.intent.IntentEvent) LinkEvent(org.onosproject.net.link.LinkEvent) MastershipEvent(org.onosproject.mastership.MastershipEvent) HostEvent(org.onosproject.net.host.HostEvent) Event(org.onosproject.event.Event) TopologyEvent(org.onosproject.net.topology.TopologyEvent) ClusterEvent(org.onosproject.cluster.ClusterEvent) DeviceEvent(org.onosproject.net.device.DeviceEvent) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode) IntentEvent(org.onosproject.net.intent.IntentEvent)

Example 3 with ClusterEvent

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));
    }
}
Also used : ClusterEvent(org.onosproject.cluster.ClusterEvent) ArrayList(java.util.ArrayList) ControllerNode(org.onosproject.cluster.ControllerNode)

Example 4 with ClusterEvent

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();
            }
        }
    }
}
Also used : AtomicValueEvent(org.onosproject.store.service.AtomicValueEvent) AppGuard.checkPermission(org.onosproject.security.AppGuard.checkPermission) CLUSTER_EVENT(org.onosproject.security.AppPermission.Type.CLUSTER_EVENT) CoordinationService(org.onosproject.store.service.CoordinationService) AtomicReference(java.util.concurrent.atomic.AtomicReference) ControllerNode(org.onosproject.cluster.ControllerNode) AtomicValue(org.onosproject.store.service.AtomicValue) Component(org.osgi.service.component.annotations.Component) Upgrade(org.onosproject.upgrade.Upgrade) VersionService(org.onosproject.core.VersionService) Version(org.onosproject.core.Version) Activate(org.osgi.service.component.annotations.Activate) KryoNamespaces(org.onosproject.store.serializers.KryoNamespaces) NodeId(org.onosproject.cluster.NodeId) UpgradeEventListener(org.onosproject.upgrade.UpgradeEventListener) Serializer(org.onosproject.store.service.Serializer) ClusterEventListener(org.onosproject.cluster.ClusterEventListener) UpgradeService(org.onosproject.upgrade.UpgradeService) Logger(org.slf4j.Logger) UPGRADE_EVENT(org.onosproject.security.AppPermission.Type.UPGRADE_EVENT) UPGRADE_READ(org.onosproject.security.AppPermission.Type.UPGRADE_READ) ClusterEvent(org.onosproject.cluster.ClusterEvent) AbstractListenerManager(org.onosproject.event.AbstractListenerManager) Deactivate(org.osgi.service.component.annotations.Deactivate) Set(java.util.Set) Collectors(java.util.stream.Collectors) AtomicValueEventListener(org.onosproject.store.service.AtomicValueEventListener) ReferenceCardinality(org.osgi.service.component.annotations.ReferenceCardinality) Objects(java.util.Objects) UpgradeEvent(org.onosproject.upgrade.UpgradeEvent) UpgradeAdminService(org.onosproject.upgrade.UpgradeAdminService) MembershipService(org.onosproject.cluster.MembershipService) LoggerFactory.getLogger(org.slf4j.LoggerFactory.getLogger) ClusterService(org.onosproject.cluster.ClusterService) UPGRADE_WRITE(org.onosproject.security.AppPermission.Type.UPGRADE_WRITE) Reference(org.osgi.service.component.annotations.Reference) NodeId(org.onosproject.cluster.NodeId) ControllerNode(org.onosproject.cluster.ControllerNode) Upgrade(org.onosproject.upgrade.Upgrade)

Example 5 with ClusterEvent

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());
}
Also used : ClusterEvent(org.onosproject.cluster.ClusterEvent) Upgrade(org.onosproject.upgrade.Upgrade) Test(org.junit.Test)

Aggregations

ClusterEvent (org.onosproject.cluster.ClusterEvent)5 ControllerNode (org.onosproject.cluster.ControllerNode)2 Event (org.onosproject.event.Event)2 MastershipEvent (org.onosproject.mastership.MastershipEvent)2 Link (org.onosproject.net.Link)2 DeviceEvent (org.onosproject.net.device.DeviceEvent)2 HostEvent (org.onosproject.net.host.HostEvent)2 IntentEvent (org.onosproject.net.intent.IntentEvent)2 LinkEvent (org.onosproject.net.link.LinkEvent)2 Topology (org.onosproject.net.topology.Topology)2 TopologyEvent (org.onosproject.net.topology.TopologyEvent)2 Upgrade (org.onosproject.upgrade.Upgrade)2 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)1 JsonNode (com.fasterxml.jackson.databind.JsonNode)1 ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)1 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)1 MoreObjects (com.google.common.base.MoreObjects)1 ImmutableList (com.google.common.collect.ImmutableList)1 PrintWriter (java.io.PrintWriter)1 StringWriter (java.io.StringWriter)1