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);
}
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);
}
Aggregations