Search in sources :

Example 21 with ClusterService

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);
}
Also used : ClusterService(org.onosproject.cluster.ClusterService) StringsCompleter(org.apache.karaf.shell.support.completers.StringsCompleter) ControllerNode(org.onosproject.cluster.ControllerNode)

Example 22 with ClusterService

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()));
}
Also used : ClusterService(org.onosproject.cluster.ClusterService) IpAddress(org.onlab.packet.IpAddress)

Example 23 with ClusterService

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()));
}
Also used : TestEventDispatcher(org.onosproject.common.event.impl.TestEventDispatcher) ComponentConfigAdapter(org.onosproject.cfg.ComponentConfigAdapter) ClusterService(org.onosproject.cluster.ClusterService) SimpleFlowRuleStore(org.onosproject.store.trivial.SimpleFlowRuleStore) NodeId(org.onosproject.cluster.NodeId) DefaultDriver(org.onosproject.net.driver.DefaultDriver) DriverRegistryManager(org.onosproject.net.driver.impl.DriverRegistryManager) Before(org.junit.Before)

Example 24 with ClusterService

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);
}
Also used : StorageAdminService(org.onosproject.store.service.StorageAdminService) STORAGE_WRITE(org.onosproject.security.AppPermission.Type.STORAGE_WRITE) PersistenceService(org.onosproject.persistence.PersistenceService) Member(org.onosproject.cluster.Member) EventuallyConsistentMapBuilder(org.onosproject.store.service.EventuallyConsistentMapBuilder) Atomix(io.atomix.core.Atomix) AtomicCounterMapBuilder(org.onosproject.store.service.AtomicCounterMapBuilder) StorageService(org.onosproject.store.service.StorageService) MapInfo(org.onosproject.store.service.MapInfo) WorkQueueStats(org.onosproject.store.service.WorkQueueStats) Map(java.util.Map) ConsistentMultimapBuilder(org.onosproject.store.service.ConsistentMultimapBuilder) KryoNamespaces(org.onosproject.store.serializers.KryoNamespaces) AtomicCounterBuilder(org.onosproject.store.service.AtomicCounterBuilder) NodeId(org.onosproject.cluster.NodeId) Serializer(org.onosproject.store.service.Serializer) LeaderElectorBuilder(org.onosproject.store.service.LeaderElectorBuilder) DocumentTreeBuilder(org.onosproject.store.service.DocumentTreeBuilder) Deactivate(org.osgi.service.component.annotations.Deactivate) Collection(java.util.Collection) TransactionId(org.onosproject.store.primitives.TransactionId) PartitionGroup(io.atomix.primitive.partition.PartitionGroup) Collectors(java.util.stream.Collectors) ConsistentTreeMapBuilder(org.onosproject.store.service.ConsistentTreeMapBuilder) List(java.util.List) AtomicCounter(io.atomix.core.counter.AtomicCounter) AsyncConsistentTreeMap(org.onosproject.store.service.AsyncConsistentTreeMap) ClusterCommunicationService(org.onosproject.store.cluster.messaging.ClusterCommunicationService) ClusterService(org.onosproject.cluster.ClusterService) DistributedSetBuilder(org.onosproject.store.service.DistributedSetBuilder) AtomicMapType(io.atomix.core.map.AtomicMapType) DistributedLockBuilder(org.onosproject.store.service.DistributedLockBuilder) AtomicCounterType(io.atomix.core.counter.AtomicCounterType) AtomicIdGeneratorBuilder(org.onosproject.store.service.AtomicIdGeneratorBuilder) WorkQueue(org.onosproject.store.service.WorkQueue) TopicBuilder(org.onosproject.store.service.TopicBuilder) AppGuard.checkPermission(org.onosproject.security.AppGuard.checkPermission) MultiRaftProtocol(io.atomix.protocols.raft.MultiRaftProtocol) AtomixManager(org.onosproject.store.atomix.impl.AtomixManager) Supplier(java.util.function.Supplier) ControllerNode(org.onosproject.cluster.ControllerNode) Component(org.osgi.service.component.annotations.Component) AtomicValueBuilder(org.onosproject.store.service.AtomicValueBuilder) Activate(org.osgi.service.component.annotations.Activate) WorkQueueType(io.atomix.core.workqueue.WorkQueueType) AsyncDocumentTree(org.onosproject.store.service.AsyncDocumentTree) WorkQueueBuilder(org.onosproject.store.service.WorkQueueBuilder) Logger(org.slf4j.Logger) Topic(org.onosproject.store.service.Topic) PartitionAdminService(org.onosproject.store.primitives.PartitionAdminService) AsyncConsistentMultimap(org.onosproject.store.service.AsyncConsistentMultimap) ConsistentMapBuilder(org.onosproject.store.service.ConsistentMapBuilder) Maps(com.google.common.collect.Maps) ReferenceCardinality(org.osgi.service.component.annotations.ReferenceCardinality) TransactionContextBuilder(org.onosproject.store.service.TransactionContextBuilder) MembershipService(org.onosproject.cluster.MembershipService) LoggerFactory.getLogger(org.slf4j.LoggerFactory.getLogger) Reference(org.osgi.service.component.annotations.Reference) ClusterService(org.onosproject.cluster.ClusterService) MembershipService(org.onosproject.cluster.MembershipService) NodeId(org.onosproject.cluster.NodeId) ControllerNode(org.onosproject.cluster.ControllerNode) List(java.util.List) Member(org.onosproject.cluster.Member)

Example 25 with ClusterService

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);
}
Also used : UiGlyph(org.onosproject.ui.UiGlyph) ClusterService(org.onosproject.cluster.ClusterService) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) UiExtensionService(org.onosproject.ui.UiExtensionService) ControllerNode(org.onosproject.cluster.ControllerNode) IpAddress(org.onlab.packet.IpAddress) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode)

Aggregations

ClusterService (org.onosproject.cluster.ClusterService)25 NodeId (org.onosproject.cluster.NodeId)17 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)8 ControllerNode (org.onosproject.cluster.ControllerNode)8 GET (javax.ws.rs.GET)6 Path (javax.ws.rs.Path)6 Produces (javax.ws.rs.Produces)6 ControlPlaneMonitorService (org.onosproject.cpman.ControlPlaneMonitorService)6 ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)5 Set (java.util.Set)4 ExecutorService (java.util.concurrent.ExecutorService)3 Collectors (java.util.stream.Collectors)3 Command (org.apache.karaf.shell.api.action.Command)3 Option (org.apache.karaf.shell.api.action.Option)3 Before (org.junit.Before)3 IpAddress (org.onlab.packet.IpAddress)3 Sets (com.google.common.collect.Sets)2 Instant (java.time.Instant)2 Collection (java.util.Collection)2 Executors.newSingleThreadScheduledExecutor (java.util.concurrent.Executors.newSingleThreadScheduledExecutor)2