Search in sources :

Example 41 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 42 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)

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