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