use of org.onosproject.cluster.ControllerNode in project onos by opennetworkinglab.
the class NodeIdCompleter method complete.
@Override
public int complete(Session session, CommandLine commandLine, List<String> candidates) {
// Delegate string completer
StringsCompleter delegate = new StringsCompleter();
// Fetch our service and feed it's offerings to the string completer
ClusterService service = AbstractShellCommand.get(ClusterService.class);
Iterator<ControllerNode> it = service.getNodes().iterator();
SortedSet<String> strings = delegate.getStrings();
while (it.hasNext()) {
strings.add(it.next().id().toString());
}
// Now let the completer do the work for figuring out what to offer.
return delegate.complete(session, commandLine, candidates);
}
use of org.onosproject.cluster.ControllerNode in project onos by opennetworkinglab.
the class NodesListCommand method json.
// Produces JSON structure.
private JsonNode json(ClusterAdminService service, List<ControllerNode> nodes) {
ObjectMapper mapper = new ObjectMapper();
ArrayNode result = mapper.createArrayNode();
ControllerNode self = service.getLocalNode();
for (ControllerNode node : nodes) {
ControllerNode.State nodeState = service.getState(node.id());
Version nodeVersion = service.getVersion(node.id());
IpAddress nodeIp = node.ip();
ObjectNode newNode = mapper.createObjectNode().put("id", node.id().toString()).put("ip", nodeIp != null ? nodeIp.toString() : node.host()).put("tcpPort", node.tcpPort()).put("self", node.equals(self));
if (nodeState != null) {
newNode.put("state", nodeState.toString());
}
if (nodeVersion != null) {
newNode.put("version", nodeVersion.toString());
}
result.add(newNode);
}
return result;
}
use of org.onosproject.cluster.ControllerNode in project onos by opennetworkinglab.
the class SimpleVirtualMastershipStore method createFakeClusterService.
/**
* Returns a fake cluster service for a test purpose only.
*
* @return a fake cluster service
*/
private ClusterService createFakeClusterService() {
// just for ease of unit test
final ControllerNode instance = new DefaultControllerNode(new NodeId("local"), IpAddress.valueOf("127.0.0.1"));
ClusterService faceClusterService = new ClusterService() {
private final Instant creationTime = Instant.now();
@Override
public ControllerNode getLocalNode() {
return instance;
}
@Override
public Set<ControllerNode> getNodes() {
return ImmutableSet.of(instance);
}
@Override
public Set<Node> getConsensusNodes() {
return ImmutableSet.of();
}
@Override
public ControllerNode getNode(NodeId nodeId) {
if (instance.id().equals(nodeId)) {
return instance;
}
return null;
}
@Override
public ControllerNode.State getState(NodeId nodeId) {
if (instance.id().equals(nodeId)) {
return ControllerNode.State.ACTIVE;
} else {
return ControllerNode.State.INACTIVE;
}
}
@Override
public Version getVersion(NodeId nodeId) {
if (instance.id().equals(nodeId)) {
return versionService.version();
}
return null;
}
@Override
public Instant getLastUpdatedInstant(NodeId nodeId) {
return creationTime;
}
@Override
public void addListener(ClusterEventListener listener) {
}
@Override
public void removeListener(ClusterEventListener listener) {
}
};
return faceClusterService;
}
use of org.onosproject.cluster.ControllerNode in project onos by opennetworkinglab.
the class StorageManager method eventuallyConsistentMapBuilder.
@Override
public <K, V> EventuallyConsistentMapBuilder<K, V> eventuallyConsistentMapBuilder() {
checkPermission(STORAGE_WRITE);
// Note: NPE in the usage of ClusterService/MembershipService prevents rebooting the Karaf container.
// We need to reference these services outside the following peer suppliers.
final MembershipService membershipService = this.membershipService;
final ClusterService clusterService = this.clusterService;
final NodeId localNodeId = clusterService.getLocalNode().id();
// Use the MembershipService to provide peers for the map that are isolated within the current version.
Supplier<List<NodeId>> peersSupplier = () -> membershipService.getMembers().stream().map(Member::nodeId).filter(nodeId -> !nodeId.equals(localNodeId)).filter(id -> clusterService.getState(id).isActive()).collect(Collectors.toList());
// If this is the first node in its version, bootstrap from the previous version. Otherwise, bootstrap the
// map from members isolated within the current version.
Supplier<List<NodeId>> bootstrapPeersSupplier = () -> {
if (membershipService.getMembers().size() == 1) {
return clusterService.getNodes().stream().map(ControllerNode::id).filter(id -> !localNodeId.equals(id)).filter(id -> clusterService.getState(id).isActive()).collect(Collectors.toList());
} else {
return membershipService.getMembers().stream().map(Member::nodeId).filter(id -> !localNodeId.equals(id)).filter(id -> clusterService.getState(id).isActive()).collect(Collectors.toList());
}
};
return new EventuallyConsistentMapBuilderImpl<>(localNodeId, clusterCommunicator, persistenceService, peersSupplier, bootstrapPeersSupplier);
}
use of org.onosproject.cluster.ControllerNode in project onos by opennetworkinglab.
the class AtomixClusterStore method activate.
@Activate
public void activate() {
membershipService = atomixManager.getAtomix().getMembershipService();
membershipService.addListener(membershipEventListener);
membershipService.getMembers().forEach(member -> {
ControllerNode node = toControllerNode(member);
nodes.put(node.id(), node);
updateState(node, member);
updateVersion(node, member);
});
membershipService.getLocalMember().properties().put(STATE_KEY, ControllerNode.State.ACTIVE.name());
membershipService.getLocalMember().properties().put(VERSION_KEY, versionService.version().toString());
localNode = toControllerNode(membershipService.getLocalMember());
states.put(localNode.id(), ControllerNode.State.ACTIVE);
versions.put(localNode.id(), versionService.version());
log.info("Started");
}
Aggregations