Search in sources :

Example 26 with ControllerNode

use of org.onosproject.cluster.ControllerNode in project onos by opennetworkinglab.

the class ClusterCommunicationManager method sendAndReceive.

private CompletableFuture<byte[]> sendAndReceive(MessageSubject subject, byte[] payload, NodeId toNodeId, Duration timeout) {
    ControllerNode node = clusterService.getNode(toNodeId);
    checkArgument(node != null, "Unknown nodeId: %s", toNodeId);
    Endpoint nodeEp = new Endpoint(node.ip(), node.tcpPort());
    MeteringAgent.Context epContext = endpointMeteringAgent.startTimer(NODE_PREFIX + toNodeId.toString() + ROUND_TRIP_SUFFIX);
    MeteringAgent.Context subjectContext = subjectMeteringAgent.startTimer(subject.toString() + ROUND_TRIP_SUFFIX);
    return messagingService.sendAndReceive(nodeEp, subject.toString(), payload, timeout).whenComplete((bytes, throwable) -> {
        subjectContext.stop(throwable);
        epContext.stop(throwable);
    });
}
Also used : Endpoint(org.onosproject.store.cluster.messaging.Endpoint) ControllerNode(org.onosproject.cluster.ControllerNode) MeteringAgent(org.onosproject.utils.MeteringAgent)

Example 27 with ControllerNode

use of org.onosproject.cluster.ControllerNode 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 28 with ControllerNode

use of org.onosproject.cluster.ControllerNode in project onos by opennetworkinglab.

the class TopologyViewMessageHandlerBase method instanceMessage.

// Produces a cluster instance message to the client.
protected ObjectNode instanceMessage(ClusterEvent event, String msgType) {
    ControllerNode node = event.subject();
    IpAddress nodeIp = node.ip();
    int switchCount = services.mastership().getDevicesOf(node.id()).size();
    ObjectNode payload = objectNode().put("id", node.id().toString()).put("ip", nodeIp != null ? nodeIp.toString() : node.host()).put("online", services.cluster().getState(node.id()).isActive()).put("ready", services.cluster().getState(node.id()).isReady()).put("uiAttached", node.equals(services.cluster().getLocalNode())).put("switches", switchCount);
    ArrayNode labels = arrayNode();
    labels.add(node.id().toString());
    labels.add(nodeIp != null ? nodeIp.toString() : node.host());
    // Add labels, props and stuff the payload into envelope.
    payload.set("labels", labels);
    addMetaUi(node.id().toString(), payload);
    String type = msgType != null ? msgType : CLUSTER_EVENT.get(event.type());
    return JsonUtils.envelope(type, payload);
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) ControllerNode(org.onosproject.cluster.ControllerNode) IpAddress(org.onlab.packet.IpAddress) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode) TopoUtils.compactLinkString(org.onosproject.ui.topo.TopoUtils.compactLinkString) ConnectPoint(org.onosproject.net.ConnectPoint)

Example 29 with ControllerNode

use of org.onosproject.cluster.ControllerNode in project onos by opennetworkinglab.

the class UiWebSocket method sendBootstrapData.

// Sends initial information (username and cluster member information)
// to allow GUI to display logged-in user, and to be able to
// fail-over to an alternate cluster member if necessary.
private void sendBootstrapData() {
    ClusterService service = directory.get(ClusterService.class);
    ArrayNode instances = arrayNode();
    for (ControllerNode node : service.getNodes()) {
        IpAddress nodeIp = node.ip();
        ObjectNode instance = objectNode().put(ID, node.id().toString()).put(IP, nodeIp != null ? nodeIp.toString() : node.host()).put(GlyphConstants.UI_ATTACHED, node.equals(service.getLocalNode()));
        instances.add(instance);
    }
    ArrayNode glyphInstances = arrayNode();
    UiExtensionService uiExtensionService = directory.get(UiExtensionService.class);
    for (UiGlyph glyph : uiExtensionService.getGlyphs()) {
        ObjectNode glyphInstance = objectNode().put(GlyphConstants.ID, glyph.id()).put(GlyphConstants.VIEWBOX, glyph.viewbox()).put(GlyphConstants.PATH, glyph.path());
        glyphInstances.add(glyphInstance);
    }
    ObjectNode payload = objectNode();
    payload.set(CLUSTER_NODES, instances);
    payload.set(GLYPHS, glyphInstances);
    payload.put(USER, userName);
    sendMessage(BOOTSTRAP, payload);
}
Also used : UiGlyph(org.onosproject.ui.UiGlyph) ClusterService(org.onosproject.cluster.ClusterService) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) UiExtensionService(org.onosproject.ui.UiExtensionService) ControllerNode(org.onosproject.cluster.ControllerNode) IpAddress(org.onlab.packet.IpAddress) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode)

Example 30 with ControllerNode

use of org.onosproject.cluster.ControllerNode in project onos by opennetworkinglab.

the class ModelCache method loadClusterMembers.

private void loadClusterMembers() {
    for (ControllerNode n : services.cluster().getNodes()) {
        UiClusterMember member = addNewClusterMember(n);
        updateClusterMember(member);
    }
}
Also used : UiClusterMember(org.onosproject.ui.model.topo.UiClusterMember) ControllerNode(org.onosproject.cluster.ControllerNode)

Aggregations

ControllerNode (org.onosproject.cluster.ControllerNode)42 NodeId (org.onosproject.cluster.NodeId)17 ClusterService (org.onosproject.cluster.ClusterService)14 Activate (org.osgi.service.component.annotations.Activate)11 Set (java.util.Set)10 DefaultControllerNode (org.onosproject.cluster.DefaultControllerNode)10 List (java.util.List)8 Collectors (java.util.stream.Collectors)8 Logger (org.slf4j.Logger)8 LoggerFactory.getLogger (org.slf4j.LoggerFactory.getLogger)8 DeviceId (org.onosproject.net.DeviceId)7 IpAddress (org.onlab.packet.IpAddress)6 Version (org.onosproject.core.Version)6 Component (org.osgi.service.component.annotations.Component)5 Deactivate (org.osgi.service.component.annotations.Deactivate)5 Reference (org.osgi.service.component.annotations.Reference)5 ReferenceCardinality (org.osgi.service.component.annotations.ReferenceCardinality)5 Preconditions.checkNotNull (com.google.common.base.Preconditions.checkNotNull)4 Collection (java.util.Collection)4 HashSet (java.util.HashSet)4