Search in sources :

Example 1 with MembershipService

use of org.onosproject.cluster.MembershipService in project onos by opennetworkinglab.

the class MembershipsListCommand method doExecute.

@Override
protected void doExecute() {
    MembershipService service = get(MembershipService.class);
    ClusterAdminService clusterService = get(ClusterAdminService.class);
    if (outputJson()) {
        print("%s", json(service));
    } else {
        service.getGroups().forEach(group -> {
            List<Member> members = newArrayList(group.members());
            print("-------------------------------------------------------------------");
            print("Version: %s, Members: %d", group.version(), members.size());
            members.sort(MEMBERSHIP_COMPARATOR);
            members.forEach(member -> {
                Optional<ControllerNode> controllerNode = Optional.ofNullable(clusterService.getNode(member.nodeId()));
                if (!controllerNode.isPresent()) {
                    print(" id=%s, version=%s, self=%s", member.nodeId(), member.version(), member.equals(service.getLocalMember()) ? "*" : "");
                } else {
                    ControllerNode node = controllerNode.get();
                    print(" id=%s, ip=%s, tcpPort=%s, state=%s, self=%s", member.nodeId(), node.ip(), node.tcpPort(), clusterService.getState(node.id()), member.equals(service.getLocalMember()) ? "*" : "");
                }
            });
            print("-------------------------------------------------------------------");
        });
    }
}
Also used : ClusterAdminService(org.onosproject.cluster.ClusterAdminService) MembershipService(org.onosproject.cluster.MembershipService) ControllerNode(org.onosproject.cluster.ControllerNode) Member(org.onosproject.cluster.Member)

Example 2 with MembershipService

use of org.onosproject.cluster.MembershipService 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)

Aggregations

ControllerNode (org.onosproject.cluster.ControllerNode)2 Member (org.onosproject.cluster.Member)2 MembershipService (org.onosproject.cluster.MembershipService)2 Maps (com.google.common.collect.Maps)1 Atomix (io.atomix.core.Atomix)1 AtomicCounter (io.atomix.core.counter.AtomicCounter)1 AtomicCounterType (io.atomix.core.counter.AtomicCounterType)1 AtomicMapType (io.atomix.core.map.AtomicMapType)1 WorkQueueType (io.atomix.core.workqueue.WorkQueueType)1 PartitionGroup (io.atomix.primitive.partition.PartitionGroup)1 MultiRaftProtocol (io.atomix.protocols.raft.MultiRaftProtocol)1 Collection (java.util.Collection)1 List (java.util.List)1 Map (java.util.Map)1 Supplier (java.util.function.Supplier)1 Collectors (java.util.stream.Collectors)1 ClusterAdminService (org.onosproject.cluster.ClusterAdminService)1 ClusterService (org.onosproject.cluster.ClusterService)1 NodeId (org.onosproject.cluster.NodeId)1 PersistenceService (org.onosproject.persistence.PersistenceService)1