use of org.onosproject.cluster.ControllerNode in project onos by opennetworkinglab.
the class Topo2Jsonifier method jsonCommon.
private ObjectNode jsonCommon(UiClusterMember member) {
ControllerNode.State state = clusterService.getState(member.id());
ControllerNode node = member.backingNode();
if (node != null) {
IpAddress nodeIp = member.backingNode().ip();
return objectNode().put("id", member.idAsString()).put("ip", nodeIp != null ? nodeIp.toString() : node.host()).put("online", state.isActive()).put("ready", state.isReady());
}
return objectNode().put("id", member.idAsString()).put("ip", "NONE").put("online", false).put("ready", false);
}
use of org.onosproject.cluster.ControllerNode 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));
}
}
use of org.onosproject.cluster.ControllerNode in project onos by opennetworkinglab.
the class DistributedApplicationStore method fetchBits.
/**
* Fetches the bits from the cluster peers.
*/
private void fetchBits(Application app, boolean delegateInstallation) {
ControllerNode localNode = clusterService.getLocalNode();
CountDownLatch latch = new CountDownLatch(1);
// FIXME: send message with name & version to make sure we don't get served old bits
log.info("Downloading bits for application {} for version : {}", app.id().name(), app.version());
for (ControllerNode node : clusterService.getNodes()) {
if (latch.getCount() == 0) {
break;
}
if (node.equals(localNode)) {
continue;
}
clusterCommunicator.sendAndReceive(app.id().name(), APP_BITS_REQUEST, s -> s.getBytes(Charsets.UTF_8), Function.identity(), node.id()).whenCompleteAsync((bits, error) -> {
if (error == null && latch.getCount() > 0) {
saveApplication(new ByteArrayInputStream(bits));
log.info("Downloaded bits for application {} from node {}", app.id().name(), node.id());
latch.countDown();
if (delegateInstallation) {
if (log.isTraceEnabled()) {
log.trace("Delegate installation for {}", app.id());
}
notifyDelegate(new ApplicationEvent(APP_INSTALLED, app));
}
} else if (error != null) {
log.warn("Unable to fetch bits for application {} from node {}", app.id().name(), node.id());
}
}, messageHandlingExecutor);
}
try {
if (!latch.await(FETCH_TIMEOUT_MS, MILLISECONDS)) {
log.warn("Unable to fetch bits for application {}", app.id().name());
}
} catch (InterruptedException e) {
log.warn("Interrupted while fetching bits for application {}", app.id().name());
Thread.currentThread().interrupt();
}
}
use of org.onosproject.cluster.ControllerNode in project onos by opennetworkinglab.
the class GossipIntentStore method getRandomNode.
private List<NodeId> getRandomNode() {
NodeId me = clusterService.getLocalNode().id();
List<NodeId> nodes = clusterService.getNodes().stream().map(ControllerNode::id).filter(node -> !Objects.equals(node, me)).collect(Collectors.toList());
if (nodes.isEmpty()) {
return ImmutableList.of();
}
return ImmutableList.of(nodes.get(RandomUtils.nextInt(nodes.size())));
}
use of org.onosproject.cluster.ControllerNode in project onos by opennetworkinglab.
the class ClusterCommunicationManager method doUnicast.
private CompletableFuture<Void> doUnicast(MessageSubject subject, byte[] payload, NodeId toNodeId) {
ControllerNode node = clusterService.getNode(toNodeId);
checkArgument(node != null, "Unknown nodeId: %s", toNodeId);
Endpoint nodeEp = new Endpoint(node.ip(), node.tcpPort());
MeteringAgent.Context context = subjectMeteringAgent.startTimer(subject.toString() + ONE_WAY_SUFFIX);
return messagingService.sendAsync(nodeEp, subject.toString(), payload).whenComplete((r, e) -> context.stop(e));
}
Aggregations