Search in sources :

Example 6 with MastershipInfo

use of org.onosproject.mastership.MastershipInfo in project onos by opennetworkinglab.

the class SimpleVirtualMastershipStore method getMastership.

@Override
public MastershipInfo getMastership(NetworkId networkId, DeviceId deviceId) {
    Map<DeviceId, NodeId> masterMap = getMasterMap(networkId);
    Map<DeviceId, AtomicInteger> termMap = getTermMap(networkId);
    Map<DeviceId, List<NodeId>> backups = getBackups(networkId);
    ImmutableMap.Builder<NodeId, MastershipRole> roleBuilder = ImmutableMap.builder();
    NodeId master = masterMap.get(deviceId);
    if (master != null) {
        roleBuilder.put(master, MastershipRole.MASTER);
    }
    backups.getOrDefault(deviceId, Collections.emptyList()).forEach(nodeId -> roleBuilder.put(nodeId, MastershipRole.STANDBY));
    clusterService.getNodes().stream().filter(node -> !masterMap.containsValue(node.id())).filter(node -> !backups.get(deviceId).contains(node.id())).forEach(node -> roleBuilder.put(node.id(), MastershipRole.NONE));
    return new MastershipInfo(termMap.getOrDefault(deviceId, new AtomicInteger(NOTHING)).get(), Optional.ofNullable(master), roleBuilder.build());
}
Also used : HashMap(java.util.HashMap) CompletableFuture(java.util.concurrent.CompletableFuture) ControllerNode(org.onosproject.cluster.ControllerNode) DefaultControllerNode(org.onosproject.cluster.DefaultControllerNode) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) MastershipEvent(org.onosproject.mastership.MastershipEvent) Component(org.osgi.service.component.annotations.Component) ImmutableList(com.google.common.collect.ImmutableList) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Node(org.onosproject.cluster.Node) VersionService(org.onosproject.core.VersionService) BACKUPS_CHANGED(org.onosproject.mastership.MastershipEvent.Type.BACKUPS_CHANGED) Map(java.util.Map) Version(org.onosproject.core.Version) NetworkId(org.onosproject.incubator.net.virtual.NetworkId) Activate(org.osgi.service.component.annotations.Activate) IpAddress(org.onlab.packet.IpAddress) NodeId(org.onosproject.cluster.NodeId) ClusterEventListener(org.onosproject.cluster.ClusterEventListener) ImmutableSet(com.google.common.collect.ImmutableSet) Logger(org.slf4j.Logger) MASTER_CHANGED(org.onosproject.mastership.MastershipEvent.Type.MASTER_CHANGED) ImmutableMap(com.google.common.collect.ImmutableMap) MastershipRole(org.onosproject.net.MastershipRole) Deactivate(org.osgi.service.component.annotations.Deactivate) VirtualNetworkMastershipStore(org.onosproject.incubator.net.virtual.VirtualNetworkMastershipStore) MastershipInfo(org.onosproject.mastership.MastershipInfo) Set(java.util.Set) Instant(java.time.Instant) MastershipTerm(org.onosproject.mastership.MastershipTerm) ReferenceCardinality(org.osgi.service.component.annotations.ReferenceCardinality) Objects(java.util.Objects) List(java.util.List) LoggerFactory.getLogger(org.slf4j.LoggerFactory.getLogger) Optional(java.util.Optional) ClusterService(org.onosproject.cluster.ClusterService) RoleInfo(org.onosproject.cluster.RoleInfo) DeviceId(org.onosproject.net.DeviceId) Reference(org.osgi.service.component.annotations.Reference) Collections(java.util.Collections) MastershipStoreDelegate(org.onosproject.mastership.MastershipStoreDelegate) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) DeviceId(org.onosproject.net.DeviceId) NodeId(org.onosproject.cluster.NodeId) MastershipInfo(org.onosproject.mastership.MastershipInfo) ArrayList(java.util.ArrayList) ImmutableList(com.google.common.collect.ImmutableList) List(java.util.List) MastershipRole(org.onosproject.net.MastershipRole) ImmutableMap(com.google.common.collect.ImmutableMap)

Aggregations

MastershipInfo (org.onosproject.mastership.MastershipInfo)6 NodeId (org.onosproject.cluster.NodeId)4 MastershipRole (org.onosproject.net.MastershipRole)3 ImmutableMap (com.google.common.collect.ImmutableMap)2 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)2 Test (org.junit.Test)2 RoleInfo (org.onosproject.cluster.RoleInfo)2 MastershipEvent (org.onosproject.mastership.MastershipEvent)2 ImmutableList (com.google.common.collect.ImmutableList)1 ImmutableSet (com.google.common.collect.ImmutableSet)1 Instant (java.time.Instant)1 ArrayList (java.util.ArrayList)1 Collections (java.util.Collections)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 List (java.util.List)1 Map (java.util.Map)1 Objects (java.util.Objects)1 Optional (java.util.Optional)1 Set (java.util.Set)1