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);
}
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);
}
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;
}
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;
}
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;
}
Aggregations