Search in sources :

Example 36 with NodeId

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

the class RoleInfoProtoTranslator method translate.

/**
 * Translates gRPC RoleInfo to {@link RoleInfo}.
 *
 * @param roleInfo gRPC message
 * @return {@link RoleInfo}
 */
public static RoleInfo translate(RoleInfoProtoOuterClass.RoleInfoProto roleInfo) {
    NodeId master = NodeIdProtoTranslator.translate(roleInfo.getMaster());
    List<NodeId> backups = Lists.newArrayList();
    backups = roleInfo.getBackupsList().stream().map(r -> NodeIdProtoTranslator.translate(r)).collect(Collectors.toList());
    return new RoleInfo(master, backups);
}
Also used : RoleInfo(org.onosproject.cluster.RoleInfo) NodeId(org.onosproject.cluster.NodeId)

Example 37 with NodeId

use of org.onosproject.cluster.NodeId 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 38 with NodeId

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

the class EventuallyConsistentMapImpl method antiEntropyCheckLocalItems.

/**
 * Processes anti-entropy ad from peer by taking following actions:
 * 1. If peer has an old entry, updates peer.
 * 2. If peer indicates an entry is removed and has a more recent
 * timestamp than the local entry, update local state.
 */
private List<EventuallyConsistentMapEvent<K, V>> antiEntropyCheckLocalItems(AntiEntropyAdvertisement<K> ad) {
    final List<EventuallyConsistentMapEvent<K, V>> externalEvents = Lists.newLinkedList();
    final NodeId sender = ad.sender();
    final List<NodeId> peers = ImmutableList.of(sender);
    Set<K> staleOrMissing = new HashSet<>();
    Set<K> locallyUnknown = new HashSet<>(ad.digest().keySet());
    items.forEach((key, localValue) -> {
        locallyUnknown.remove(key);
        MapValue.Digest remoteValueDigest = ad.digest().get(key);
        if (remoteValueDigest == null || localValue.isNewerThan(remoteValueDigest.timestamp())) {
            // local value is more recent, push to sender
            queueUpdate(new UpdateEntry<>(key, localValue), peers);
        } else if (remoteValueDigest.isNewerThan(localValue.digest()) && remoteValueDigest.isTombstone()) {
            // remote value is more recent and a tombstone: update local value
            MapValue<V> tombstone = MapValue.tombstone(remoteValueDigest.timestamp());
            MapValue<V> previousValue = removeInternal(key, Optional.empty(), Optional.of(tombstone));
            if (previousValue != null && previousValue.isAlive()) {
                externalEvents.add(new EventuallyConsistentMapEvent<>(mapName, REMOVE, key, previousValue.get()));
            }
        } else if (remoteValueDigest.isNewerThan(localValue.digest())) {
            // Not a tombstone and remote is newer
            staleOrMissing.add(key);
        }
    });
    // Keys missing in local map
    staleOrMissing.addAll(locallyUnknown);
    // Request updates that we missed out on
    sendUpdateRequestToPeer(sender, staleOrMissing);
    return externalEvents;
}
Also used : EventuallyConsistentMapEvent(org.onosproject.store.service.EventuallyConsistentMapEvent) NodeId(org.onosproject.cluster.NodeId) HashSet(java.util.HashSet)

Example 39 with NodeId

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

the class EventuallyConsistentMapImpl method requestBootstrapFromPeers.

/**
 * Requests all updates from each peer in the provided list of peers.
 * <p>
 * The returned future will be completed once at least one peer bootstraps this map or bootstrap requests to all
 * peers fail.
 *
 * @param peers the list of peers from which to request updates
 * @return a future to be completed once updates have been received from at least one peer
 */
private CompletableFuture<Void> requestBootstrapFromPeers(List<NodeId> peers) {
    if (peers.isEmpty()) {
        return CompletableFuture.completedFuture(null);
    }
    CompletableFuture<Void> future = new CompletableFuture<>();
    final int totalPeers = peers.size();
    AtomicBoolean successful = new AtomicBoolean();
    AtomicInteger totalCount = new AtomicInteger();
    AtomicReference<Throwable> lastError = new AtomicReference<>();
    // successful bootstrap response, the future will be completed with the last exception.
    for (NodeId peer : peers) {
        requestBootstrapFromPeer(peer).whenComplete((result, error) -> {
            if (error == null) {
                if (successful.compareAndSet(false, true)) {
                    future.complete(null);
                } else if (totalCount.incrementAndGet() == totalPeers) {
                    Throwable e = lastError.get();
                    if (e != null) {
                        future.completeExceptionally(e);
                    }
                }
            } else {
                if (!successful.get() && totalCount.incrementAndGet() == totalPeers) {
                    future.completeExceptionally(error);
                } else {
                    lastError.set(error);
                }
            }
        });
    }
    return future;
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) CompletableFuture(java.util.concurrent.CompletableFuture) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) NodeId(org.onosproject.cluster.NodeId) AtomicReference(java.util.concurrent.atomic.AtomicReference)

Example 40 with NodeId

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

the class DistributedStatisticStoreTest method setUp.

@Before
public void setUp() throws Exception {
    statStore = new DistributedStatisticStore();
    statStore.cfgService = new ComponentConfigAdapter();
    mockClusterService = createMock(ClusterService.class);
    statStore.clusterService = mockClusterService;
    statStore.clusterService = mockClusterService;
    nodeId = new NodeId("1");
    mockControllerNode = new SetMockControllerNode(nodeId);
    expect(mockClusterService.getLocalNode()).andReturn(mockControllerNode).anyTimes();
    replay(mockClusterService);
    statStore.clusterCommunicator = new ClusterCommunicationServiceAdapter();
    statStore.mastershipService = new MasterOfAll();
    statStore.activate(mockContext);
    store = statStore;
}
Also used : ComponentConfigAdapter(org.onosproject.cfg.ComponentConfigAdapter) ClusterService(org.onosproject.cluster.ClusterService) NodeId(org.onosproject.cluster.NodeId) ClusterCommunicationServiceAdapter(org.onosproject.store.cluster.messaging.ClusterCommunicationServiceAdapter) Before(org.junit.Before)

Aggregations

NodeId (org.onosproject.cluster.NodeId)145 ClusterService (org.onosproject.cluster.ClusterService)36 DeviceId (org.onosproject.net.DeviceId)36 Set (java.util.Set)26 MastershipRole (org.onosproject.net.MastershipRole)23 ControllerNode (org.onosproject.cluster.ControllerNode)22 Test (org.junit.Test)18 Activate (org.osgi.service.component.annotations.Activate)18 List (java.util.List)16 MastershipService (org.onosproject.mastership.MastershipService)15 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)13 Map (java.util.Map)12 ImmutableSet (com.google.common.collect.ImmutableSet)11 ArrayList (java.util.ArrayList)11 Collectors (java.util.stream.Collectors)11 HashSet (java.util.HashSet)10 Optional (java.util.Optional)10 ClusterCommunicationService (org.onosproject.store.cluster.messaging.ClusterCommunicationService)10 Component (org.osgi.service.component.annotations.Component)9 Deactivate (org.osgi.service.component.annotations.Deactivate)9