Search in sources :

Example 1 with EventuallyConsistentMapBuilder

use of org.onosproject.store.service.EventuallyConsistentMapBuilder in project onos by opennetworkinglab.

the class CoordinationManager method eventuallyConsistentMapBuilder.

@Override
public <K, V> EventuallyConsistentMapBuilder<K, V> eventuallyConsistentMapBuilder() {
    checkPermission(STORAGE_WRITE);
    final NodeId localNodeId = clusterService.getLocalNode().id();
    Supplier<List<NodeId>> peersSupplier = () -> clusterService.getNodes().stream().map(ControllerNode::id).filter(nodeId -> !nodeId.equals(localNodeId)).filter(id -> clusterService.getState(id).isActive()).collect(Collectors.toList());
    Supplier<List<NodeId>> bootstrapPeersSupplier = () -> clusterService.getNodes().stream().map(ControllerNode::id).filter(id -> !localNodeId.equals(id)).filter(id -> clusterService.getState(id).isActive()).collect(Collectors.toList());
    return new EventuallyConsistentMapBuilderImpl<>(localNodeId, clusterCommunicator, persistenceService, peersSupplier, bootstrapPeersSupplier);
}
Also used : WorkQueue(org.onosproject.store.service.WorkQueue) STORAGE_WRITE(org.onosproject.security.AppPermission.Type.STORAGE_WRITE) PersistenceService(org.onosproject.persistence.PersistenceService) TopicBuilder(org.onosproject.store.service.TopicBuilder) AppGuard.checkPermission(org.onosproject.security.AppGuard.checkPermission) EventuallyConsistentMapBuilder(org.onosproject.store.service.EventuallyConsistentMapBuilder) CoordinationService(org.onosproject.store.service.CoordinationService) AtomixManager(org.onosproject.store.atomix.impl.AtomixManager) Supplier(java.util.function.Supplier) ControllerNode(org.onosproject.cluster.ControllerNode) Atomix(io.atomix.core.Atomix) AtomicCounterMapBuilder(org.onosproject.store.service.AtomicCounterMapBuilder) Component(org.osgi.service.component.annotations.Component) AtomicValueBuilder(org.onosproject.store.service.AtomicValueBuilder) ConsistentMultimapBuilder(org.onosproject.store.service.ConsistentMultimapBuilder) Activate(org.osgi.service.component.annotations.Activate) AtomicCounterBuilder(org.onosproject.store.service.AtomicCounterBuilder) NodeId(org.onosproject.cluster.NodeId) Serializer(org.onosproject.store.service.Serializer) LeaderElectorBuilder(org.onosproject.store.service.LeaderElectorBuilder) AsyncDocumentTree(org.onosproject.store.service.AsyncDocumentTree) DocumentTreeBuilder(org.onosproject.store.service.DocumentTreeBuilder) WorkQueueBuilder(org.onosproject.store.service.WorkQueueBuilder) Logger(org.slf4j.Logger) Topic(org.onosproject.store.service.Topic) AsyncConsistentMultimap(org.onosproject.store.service.AsyncConsistentMultimap) Deactivate(org.osgi.service.component.annotations.Deactivate) ConsistentMapBuilder(org.onosproject.store.service.ConsistentMapBuilder) PartitionGroup(io.atomix.primitive.partition.PartitionGroup) Collectors(java.util.stream.Collectors) ConsistentTreeMapBuilder(org.onosproject.store.service.ConsistentTreeMapBuilder) ReferenceCardinality(org.osgi.service.component.annotations.ReferenceCardinality) List(java.util.List) TransactionContextBuilder(org.onosproject.store.service.TransactionContextBuilder) AsyncConsistentTreeMap(org.onosproject.store.service.AsyncConsistentTreeMap) LoggerFactory.getLogger(org.slf4j.LoggerFactory.getLogger) ClusterCommunicationService(org.onosproject.store.cluster.messaging.ClusterCommunicationService) ClusterService(org.onosproject.cluster.ClusterService) DistributedSetBuilder(org.onosproject.store.service.DistributedSetBuilder) AtomicIdGeneratorBuilder(org.onosproject.store.service.AtomicIdGeneratorBuilder) Reference(org.osgi.service.component.annotations.Reference) NodeId(org.onosproject.cluster.NodeId) List(java.util.List)

Example 2 with EventuallyConsistentMapBuilder

use of org.onosproject.store.service.EventuallyConsistentMapBuilder in project onos by opennetworkinglab.

the class GossipIntentStore method activate.

@Activate
public void activate(ComponentContext context) {
    configService.registerProperties(getClass());
    modified(context);
    // TODO persistent intents must be reevaluated and the appropriate
    // processing done here, current implementation is not functional
    // and is for performance evaluation only
    initiallyPersistent = persistenceEnabled;
    KryoNamespace.Builder intentSerializer = KryoNamespace.newBuilder().register(KryoNamespaces.API).register(IntentData.class).register(MultiValuedTimestamp.class);
    EventuallyConsistentMapBuilder currentECMapBuilder = storageService.<Key, IntentData>eventuallyConsistentMapBuilder().withName("intent-current").withSerializer(intentSerializer).withTimestampProvider(this::currentTimestampProvider).withPeerUpdateFunction((key, intentData) -> getPeerNodes(key, intentData));
    EventuallyConsistentMapBuilder pendingECMapBuilder = storageService.<Key, IntentData>eventuallyConsistentMapBuilder().withName("intent-pending").withSerializer(intentSerializer).withTimestampProvider((key, intentData) -> new MultiValuedTimestamp<>(new WallClockTimestamp(), System.nanoTime())).withPeerUpdateFunction((key, intentData) -> getPeerNodes(key, intentData));
    if (initiallyPersistent) {
        currentECMapBuilder = currentECMapBuilder.withPersistence();
        pendingECMapBuilder = pendingECMapBuilder.withPersistence();
    }
    currentMap = currentECMapBuilder.build();
    pendingMap = pendingECMapBuilder.build();
    currentMap.addListener(mapCurrentListener);
    pendingMap.addListener(mapPendingListener);
    log.info("Started");
}
Also used : IntentState(org.onosproject.net.intent.IntentState) EventuallyConsistentMapBuilder(org.onosproject.store.service.EventuallyConsistentMapBuilder) Backtrace(org.onlab.util.Backtrace) RandomUtils(org.apache.commons.lang.math.RandomUtils) StorageService(org.onosproject.store.service.StorageService) PURGE_REQ(org.onosproject.net.intent.IntentState.PURGE_REQ) KryoNamespaces(org.onosproject.store.serializers.KryoNamespaces) WorkPartitionService(org.onosproject.net.intent.WorkPartitionService) NodeId(org.onosproject.cluster.NodeId) Tools.get(org.onlab.util.Tools.get) EventuallyConsistentMapEvent(org.onosproject.store.service.EventuallyConsistentMapEvent) Deactivate(org.osgi.service.component.annotations.Deactivate) Collection(java.util.Collection) WallClockTimestamp(org.onosproject.store.service.WallClockTimestamp) Collectors(java.util.stream.Collectors) Objects(java.util.Objects) Key(org.onosproject.net.intent.Key) List(java.util.List) GIS_PERSISTENCE_ENABLED_DEFAULT(org.onosproject.store.OsgiPropertyConstants.GIS_PERSISTENCE_ENABLED_DEFAULT) Optional(java.util.Optional) ClusterService(org.onosproject.cluster.ClusterService) GIS_PERSISTENCE_ENABLED(org.onosproject.store.OsgiPropertyConstants.GIS_PERSISTENCE_ENABLED) Dictionary(java.util.Dictionary) IntentEvent(org.onosproject.net.intent.IntentEvent) ComponentContext(org.osgi.service.component.ComponentContext) Strings.isNullOrEmpty(com.google.common.base.Strings.isNullOrEmpty) KryoNamespace(org.onlab.util.KryoNamespace) IntentData(org.onosproject.net.intent.IntentData) ControllerNode(org.onosproject.cluster.ControllerNode) Component(org.osgi.service.component.annotations.Component) ImmutableList(com.google.common.collect.ImmutableList) Intent(org.onosproject.net.intent.Intent) Timestamp(org.onosproject.store.Timestamp) Activate(org.osgi.service.component.annotations.Activate) EventuallyConsistentMap(org.onosproject.store.service.EventuallyConsistentMap) EventuallyConsistentMapListener(org.onosproject.store.service.EventuallyConsistentMapListener) ComponentConfigService(org.onosproject.cfg.ComponentConfigService) Logger(org.slf4j.Logger) Properties(java.util.Properties) Preconditions.checkNotNull(com.google.common.base.Preconditions.checkNotNull) ReferenceCardinality(org.osgi.service.component.annotations.ReferenceCardinality) AtomicLong(java.util.concurrent.atomic.AtomicLong) IntentStoreDelegate(org.onosproject.net.intent.IntentStoreDelegate) MultiValuedTimestamp(org.onosproject.store.service.MultiValuedTimestamp) IntentStore(org.onosproject.net.intent.IntentStore) AbstractStore(org.onosproject.store.AbstractStore) Modified(org.osgi.service.component.annotations.Modified) LoggerFactory.getLogger(org.slf4j.LoggerFactory.getLogger) Reference(org.osgi.service.component.annotations.Reference) WallClockTimestamp(org.onosproject.store.service.WallClockTimestamp) IntentData(org.onosproject.net.intent.IntentData) EventuallyConsistentMapBuilder(org.onosproject.store.service.EventuallyConsistentMapBuilder) KryoNamespace(org.onlab.util.KryoNamespace) MultiValuedTimestamp(org.onosproject.store.service.MultiValuedTimestamp) Key(org.onosproject.net.intent.Key) Activate(org.osgi.service.component.annotations.Activate)

Example 3 with EventuallyConsistentMapBuilder

use of org.onosproject.store.service.EventuallyConsistentMapBuilder 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

List (java.util.List)3 Collectors (java.util.stream.Collectors)3 ClusterService (org.onosproject.cluster.ClusterService)3 ControllerNode (org.onosproject.cluster.ControllerNode)3 NodeId (org.onosproject.cluster.NodeId)3 EventuallyConsistentMapBuilder (org.onosproject.store.service.EventuallyConsistentMapBuilder)3 Atomix (io.atomix.core.Atomix)2 PartitionGroup (io.atomix.primitive.partition.PartitionGroup)2 Collection (java.util.Collection)2 Supplier (java.util.function.Supplier)2 PersistenceService (org.onosproject.persistence.PersistenceService)2 Activate (org.osgi.service.component.annotations.Activate)2 Component (org.osgi.service.component.annotations.Component)2 Deactivate (org.osgi.service.component.annotations.Deactivate)2 Reference (org.osgi.service.component.annotations.Reference)2 ReferenceCardinality (org.osgi.service.component.annotations.ReferenceCardinality)2 Logger (org.slf4j.Logger)2 LoggerFactory.getLogger (org.slf4j.LoggerFactory.getLogger)2 Preconditions.checkNotNull (com.google.common.base.Preconditions.checkNotNull)1 Strings.isNullOrEmpty (com.google.common.base.Strings.isNullOrEmpty)1