use of org.onosproject.cluster.ClusterService 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.ClusterService in project onos by opennetworkinglab.
the class ControllerNodeCodec method encode.
@Override
public ObjectNode encode(ControllerNode node, CodecContext context) {
checkNotNull(node, "Controller node cannot be null");
ClusterService service = context.getService(ClusterService.class);
IpAddress nodeIp = node.ip();
return context.mapper().createObjectNode().put("id", node.id().toString()).put("ip", nodeIp != null ? nodeIp.toString() : node.host()).put("tcpPort", node.tcpPort()).put("status", service.getState(node.id()).toString()).put("lastUpdate", Long.toString(service.getLastUpdatedInstant(node.id()).toEpochMilli())).put("humanReadableLastUpdate", service.localStatus(node.id()));
}
use of org.onosproject.cluster.ClusterService in project onos by opennetworkinglab.
the class FlowRuleManagerTest method setUp.
@Before
public void setUp() {
mgr = new FlowRuleManager();
mgr.store = new SimpleFlowRuleStore();
injectEventDispatcher(mgr, new TestEventDispatcher());
mgr.deviceService = new TestDeviceService();
mgr.mastershipService = new TestMastershipService();
mgr.coreService = new TestCoreService();
mgr.operationsService = MoreExecutors.newDirectExecutorService();
mgr.deviceInstallers = MoreExecutors.newDirectExecutorService();
mgr.cfgService = new ComponentConfigAdapter();
ClusterService mockClusterService = createMock(ClusterService.class);
NodeId nodeId = new NodeId(NODE_ID);
MockControllerNode mockControllerNode = new MockControllerNode(nodeId);
expect(mockClusterService.getLocalNode()).andReturn(mockControllerNode).anyTimes();
replay(mockClusterService);
mgr.clusterService = mockClusterService;
service = mgr;
registry = mgr;
DriverRegistryManager driverRegistry = new DriverRegistryManager();
driverService = new TestDriverManager(driverRegistry);
driverRegistry.addDriver(new DefaultDriver("foo", ImmutableList.of(), "", "", "", ImmutableMap.of(FlowRuleProgrammable.class, TestFlowRuleProgrammable.class), ImmutableMap.of()));
mgr.activate(null);
mgr.addListener(listener);
provider = new TestProvider(PID);
providerService = this.registry.register(provider);
appId = new TestApplicationId(0, "FlowRuleManagerTest");
assertTrue("provider should be registered", this.registry.getProviders().contains(provider.id()));
}
use of org.onosproject.cluster.ClusterService 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.ClusterService 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