list mastership roles CLI command

Change-Id: I54dc296f90c4b8ceebe4e86816c3796da4d2d714
This commit is contained in:
Ayaka Koshibe 2014-10-14 11:26:45 -07:00
parent f670a29c64
commit 45503ce0b2
8 changed files with 71 additions and 2 deletions

View File

@ -13,6 +13,10 @@
<command> <command>
<action class="org.onlab.onos.cli.NodeRemoveCommand"/> <action class="org.onlab.onos.cli.NodeRemoveCommand"/>
</command> </command>
<command>
<action class="org.onlab.onos.cli.RolesCommand"/>
</command>
<command> <command>
<action class="org.onlab.onos.cli.MastersListCommand"/> <action class="org.onlab.onos.cli.MastersListCommand"/>
<completers> <completers>

View File

@ -1,5 +1,6 @@
package org.onlab.onos.mastership; package org.onlab.onos.mastership;
import java.util.List;
import java.util.Set; import java.util.Set;
import org.onlab.onos.cluster.NodeId; import org.onlab.onos.cluster.NodeId;
@ -49,6 +50,15 @@ public interface MastershipService {
*/ */
NodeId getMasterFor(DeviceId deviceId); 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. * Returns the devices for which a controller is master.
* *

View File

@ -1,5 +1,6 @@
package org.onlab.onos.mastership; package org.onlab.onos.mastership;
import java.util.List;
import java.util.Set; import java.util.Set;
import org.onlab.onos.cluster.NodeId; import org.onlab.onos.cluster.NodeId;
@ -40,6 +41,15 @@ public interface MastershipStore extends Store<MastershipEvent, MastershipStoreD
*/ */
NodeId getMaster(DeviceId deviceId); 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. * 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); Set<DeviceId> getDevices(NodeId nodeId);
/** /**
* Sets a device's role for a specified controller instance. * Sets a device's role for a specified controller instance.
* *

View File

@ -4,6 +4,7 @@ import org.onlab.onos.cluster.NodeId;
import org.onlab.onos.net.DeviceId; import org.onlab.onos.net.DeviceId;
import org.onlab.onos.net.MastershipRole; import org.onlab.onos.net.MastershipRole;
import java.util.List;
import java.util.Set; import java.util.Set;
/** /**
@ -46,4 +47,9 @@ public class MastershipServiceAdapter implements MastershipService {
public MastershipTermService requestTermService() { public MastershipTermService requestTermService() {
return null; return null;
} }
@Override
public List<NodeId> getNodesFor(DeviceId deviceId) {
return null;
}
} }

View File

@ -3,6 +3,7 @@ package org.onlab.onos.cluster.impl;
import static com.google.common.base.Preconditions.checkNotNull; import static com.google.common.base.Preconditions.checkNotNull;
import static org.slf4j.LoggerFactory.getLogger; import static org.slf4j.LoggerFactory.getLogger;
import java.util.List;
import java.util.Set; import java.util.Set;
import java.util.concurrent.atomic.AtomicInteger; import java.util.concurrent.atomic.AtomicInteger;
@ -127,6 +128,11 @@ implements MastershipService, MastershipAdminService {
return store.getDevices(nodeId); return store.getDevices(nodeId);
} }
@Override
public List<NodeId> getNodesFor(DeviceId deviceId) {
checkNotNull(deviceId, DEVICE_ID_NULL);
return store.getNodes(deviceId);
}
@Override @Override
public MastershipTermService requestTermService() { public MastershipTermService requestTermService() {

View File

@ -54,7 +54,7 @@ public class DistributedClusterStore
@Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
private ClusterCommunicationAdminService clusterCommunicationAdminService; private ClusterCommunicationAdminService clusterCommunicationAdminService;
private final ClusterNodesDelegate nodesDelegate = new InnerNodesDelegate(); private final ClusterNodesDelegate nodesDelegate = new InternalNodesDelegate();
@Activate @Activate
public void activate() throws IOException { public void activate() throws IOException {
@ -151,7 +151,7 @@ public class DistributedClusterStore
} }
// Entity to handle back calls from the connection manager. // Entity to handle back calls from the connection manager.
private class InnerNodesDelegate implements ClusterNodesDelegate { private class InternalNodesDelegate implements ClusterNodesDelegate {
@Override @Override
public DefaultControllerNode nodeDetected(NodeId nodeId, IpPrefix ip, int tcpPort) { public DefaultControllerNode nodeDetected(NodeId nodeId, IpPrefix ip, int tcpPort) {
DefaultControllerNode node = nodes.get(nodeId); DefaultControllerNode node = nodes.get(nodeId);

View File

@ -2,6 +2,8 @@ package org.onlab.onos.store.mastership.impl;
import static org.onlab.onos.mastership.MastershipEvent.Type.MASTER_CHANGED; 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.Map;
import java.util.Set; import java.util.Set;
@ -143,6 +145,30 @@ implements MastershipStore {
return deserialize(masters.get(serialize(deviceId))); 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 @Override
public Set<DeviceId> getDevices(NodeId nodeId) { public Set<DeviceId> getDevices(NodeId nodeId) {
ImmutableSet.Builder<DeviceId> builder = ImmutableSet.builder(); ImmutableSet.Builder<DeviceId> builder = ImmutableSet.builder();

View File

@ -5,6 +5,7 @@ import static org.slf4j.LoggerFactory.getLogger;
import java.util.Collections; import java.util.Collections;
import java.util.HashMap; import java.util.HashMap;
import java.util.HashSet; import java.util.HashSet;
import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
import java.util.concurrent.atomic.AtomicInteger; import java.util.concurrent.atomic.AtomicInteger;
@ -94,6 +95,11 @@ public class SimpleMastershipStore
return masterMap.get(deviceId); return masterMap.get(deviceId);
} }
@Override
public List<NodeId> getNodes(DeviceId deviceId) {
return null;
}
@Override @Override
public Set<DeviceId> getDevices(NodeId nodeId) { public Set<DeviceId> getDevices(NodeId nodeId) {
Set<DeviceId> ids = new HashSet<>(); Set<DeviceId> ids = new HashSet<>();