mirror of
https://github.com/opennetworkinglab/onos.git
synced 2025-10-17 18:32:28 +02:00
list mastership roles CLI command
Change-Id: I54dc296f90c4b8ceebe4e86816c3796da4d2d714
This commit is contained in:
parent
f670a29c64
commit
45503ce0b2
@ -13,6 +13,10 @@
|
||||
<command>
|
||||
<action class="org.onlab.onos.cli.NodeRemoveCommand"/>
|
||||
</command>
|
||||
|
||||
<command>
|
||||
<action class="org.onlab.onos.cli.RolesCommand"/>
|
||||
</command>
|
||||
<command>
|
||||
<action class="org.onlab.onos.cli.MastersListCommand"/>
|
||||
<completers>
|
||||
|
@ -1,5 +1,6 @@
|
||||
package org.onlab.onos.mastership;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import org.onlab.onos.cluster.NodeId;
|
||||
@ -49,6 +50,15 @@ public interface MastershipService {
|
||||
*/
|
||||
NodeId getMasterFor(DeviceId deviceId);
|
||||
|
||||
/**
|
||||
* Returns controllers connected to a given device, in order of
|
||||
* preference. The first entry in the list is the current master.
|
||||
*
|
||||
* @param deviceId the identifier of the device
|
||||
* @return a list of controller IDs
|
||||
*/
|
||||
List<NodeId> getNodesFor(DeviceId deviceId);
|
||||
|
||||
/**
|
||||
* Returns the devices for which a controller is master.
|
||||
*
|
||||
|
@ -1,5 +1,6 @@
|
||||
package org.onlab.onos.mastership;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import org.onlab.onos.cluster.NodeId;
|
||||
@ -40,6 +41,15 @@ public interface MastershipStore extends Store<MastershipEvent, MastershipStoreD
|
||||
*/
|
||||
NodeId getMaster(DeviceId deviceId);
|
||||
|
||||
/**
|
||||
* Returns the controllers connected to a device, in mastership-
|
||||
* preference order.
|
||||
*
|
||||
* @param deviceId the device identifier
|
||||
* @return an ordered list of controller IDs
|
||||
*/
|
||||
List<NodeId> getNodes(DeviceId deviceId);
|
||||
|
||||
/**
|
||||
* Returns the devices that a controller instance is master of.
|
||||
*
|
||||
@ -48,6 +58,7 @@ public interface MastershipStore extends Store<MastershipEvent, MastershipStoreD
|
||||
*/
|
||||
Set<DeviceId> getDevices(NodeId nodeId);
|
||||
|
||||
|
||||
/**
|
||||
* Sets a device's role for a specified controller instance.
|
||||
*
|
||||
|
@ -4,6 +4,7 @@ import org.onlab.onos.cluster.NodeId;
|
||||
import org.onlab.onos.net.DeviceId;
|
||||
import org.onlab.onos.net.MastershipRole;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
@ -46,4 +47,9 @@ public class MastershipServiceAdapter implements MastershipService {
|
||||
public MastershipTermService requestTermService() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<NodeId> getNodesFor(DeviceId deviceId) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
@ -3,6 +3,7 @@ package org.onlab.onos.cluster.impl;
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
import static org.slf4j.LoggerFactory.getLogger;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
@ -127,6 +128,11 @@ implements MastershipService, MastershipAdminService {
|
||||
return store.getDevices(nodeId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<NodeId> getNodesFor(DeviceId deviceId) {
|
||||
checkNotNull(deviceId, DEVICE_ID_NULL);
|
||||
return store.getNodes(deviceId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public MastershipTermService requestTermService() {
|
||||
|
@ -54,7 +54,7 @@ public class DistributedClusterStore
|
||||
@Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
|
||||
private ClusterCommunicationAdminService clusterCommunicationAdminService;
|
||||
|
||||
private final ClusterNodesDelegate nodesDelegate = new InnerNodesDelegate();
|
||||
private final ClusterNodesDelegate nodesDelegate = new InternalNodesDelegate();
|
||||
|
||||
@Activate
|
||||
public void activate() throws IOException {
|
||||
@ -151,7 +151,7 @@ public class DistributedClusterStore
|
||||
}
|
||||
|
||||
// Entity to handle back calls from the connection manager.
|
||||
private class InnerNodesDelegate implements ClusterNodesDelegate {
|
||||
private class InternalNodesDelegate implements ClusterNodesDelegate {
|
||||
@Override
|
||||
public DefaultControllerNode nodeDetected(NodeId nodeId, IpPrefix ip, int tcpPort) {
|
||||
DefaultControllerNode node = nodes.get(nodeId);
|
||||
|
@ -2,6 +2,8 @@ package org.onlab.onos.store.mastership.impl;
|
||||
|
||||
import static org.onlab.onos.mastership.MastershipEvent.Type.MASTER_CHANGED;
|
||||
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
@ -143,6 +145,30 @@ implements MastershipStore {
|
||||
return deserialize(masters.get(serialize(deviceId)));
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public List<NodeId> getNodes(DeviceId deviceId) {
|
||||
byte [] did = serialize(deviceId);
|
||||
List<NodeId> nodes = new LinkedList<>();
|
||||
|
||||
//add current master to head - if there is one
|
||||
ILock lock = theInstance.getLock(LOCK);
|
||||
lock.lock();
|
||||
try {
|
||||
byte [] master = masters.get(did);
|
||||
if (master != null) {
|
||||
nodes.add((NodeId) deserialize(master));
|
||||
}
|
||||
|
||||
for (byte [] el : standbys.get(serialize(deviceId))) {
|
||||
nodes.add((NodeId) deserialize(el));
|
||||
}
|
||||
return nodes;
|
||||
} finally {
|
||||
lock.unlock();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<DeviceId> getDevices(NodeId nodeId) {
|
||||
ImmutableSet.Builder<DeviceId> builder = ImmutableSet.builder();
|
||||
|
@ -5,6 +5,7 @@ import static org.slf4j.LoggerFactory.getLogger;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
@ -94,6 +95,11 @@ public class SimpleMastershipStore
|
||||
return masterMap.get(deviceId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<NodeId> getNodes(DeviceId deviceId) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<DeviceId> getDevices(NodeId nodeId) {
|
||||
Set<DeviceId> ids = new HashSet<>();
|
||||
|
Loading…
x
Reference in New Issue
Block a user