Ayaka Koshibe

list mastership roles CLI command

Change-Id: I54dc296f90c4b8ceebe4e86816c3796da4d2d714
...@@ -13,6 +13,10 @@ ...@@ -13,6 +13,10 @@
13 <command> 13 <command>
14 <action class="org.onlab.onos.cli.NodeRemoveCommand"/> 14 <action class="org.onlab.onos.cli.NodeRemoveCommand"/>
15 </command> 15 </command>
16 +
17 + <command>
18 + <action class="org.onlab.onos.cli.RolesCommand"/>
19 + </command>
16 <command> 20 <command>
17 <action class="org.onlab.onos.cli.MastersListCommand"/> 21 <action class="org.onlab.onos.cli.MastersListCommand"/>
18 <completers> 22 <completers>
......
1 package org.onlab.onos.mastership; 1 package org.onlab.onos.mastership;
2 2
3 +import java.util.List;
3 import java.util.Set; 4 import java.util.Set;
4 5
5 import org.onlab.onos.cluster.NodeId; 6 import org.onlab.onos.cluster.NodeId;
...@@ -50,6 +51,15 @@ public interface MastershipService { ...@@ -50,6 +51,15 @@ public interface MastershipService {
50 NodeId getMasterFor(DeviceId deviceId); 51 NodeId getMasterFor(DeviceId deviceId);
51 52
52 /** 53 /**
54 + * Returns controllers connected to a given device, in order of
55 + * preference. The first entry in the list is the current master.
56 + *
57 + * @param deviceId the identifier of the device
58 + * @return a list of controller IDs
59 + */
60 + List<NodeId> getNodesFor(DeviceId deviceId);
61 +
62 + /**
53 * Returns the devices for which a controller is master. 63 * Returns the devices for which a controller is master.
54 * 64 *
55 * @param nodeId the ID of the controller 65 * @param nodeId the ID of the controller
......
1 package org.onlab.onos.mastership; 1 package org.onlab.onos.mastership;
2 2
3 +import java.util.List;
3 import java.util.Set; 4 import java.util.Set;
4 5
5 import org.onlab.onos.cluster.NodeId; 6 import org.onlab.onos.cluster.NodeId;
...@@ -41,6 +42,15 @@ public interface MastershipStore extends Store<MastershipEvent, MastershipStoreD ...@@ -41,6 +42,15 @@ public interface MastershipStore extends Store<MastershipEvent, MastershipStoreD
41 NodeId getMaster(DeviceId deviceId); 42 NodeId getMaster(DeviceId deviceId);
42 43
43 /** 44 /**
45 + * Returns the controllers connected to a device, in mastership-
46 + * preference order.
47 + *
48 + * @param deviceId the device identifier
49 + * @return an ordered list of controller IDs
50 + */
51 + List<NodeId> getNodes(DeviceId deviceId);
52 +
53 + /**
44 * Returns the devices that a controller instance is master of. 54 * Returns the devices that a controller instance is master of.
45 * 55 *
46 * @param nodeId the instance identifier 56 * @param nodeId the instance identifier
...@@ -48,6 +58,7 @@ public interface MastershipStore extends Store<MastershipEvent, MastershipStoreD ...@@ -48,6 +58,7 @@ public interface MastershipStore extends Store<MastershipEvent, MastershipStoreD
48 */ 58 */
49 Set<DeviceId> getDevices(NodeId nodeId); 59 Set<DeviceId> getDevices(NodeId nodeId);
50 60
61 +
51 /** 62 /**
52 * Sets a device's role for a specified controller instance. 63 * Sets a device's role for a specified controller instance.
53 * 64 *
......
...@@ -4,6 +4,7 @@ import org.onlab.onos.cluster.NodeId; ...@@ -4,6 +4,7 @@ import org.onlab.onos.cluster.NodeId;
4 import org.onlab.onos.net.DeviceId; 4 import org.onlab.onos.net.DeviceId;
5 import org.onlab.onos.net.MastershipRole; 5 import org.onlab.onos.net.MastershipRole;
6 6
7 +import java.util.List;
7 import java.util.Set; 8 import java.util.Set;
8 9
9 /** 10 /**
...@@ -46,4 +47,9 @@ public class MastershipServiceAdapter implements MastershipService { ...@@ -46,4 +47,9 @@ public class MastershipServiceAdapter implements MastershipService {
46 public MastershipTermService requestTermService() { 47 public MastershipTermService requestTermService() {
47 return null; 48 return null;
48 } 49 }
50 +
51 + @Override
52 + public List<NodeId> getNodesFor(DeviceId deviceId) {
53 + return null;
54 + }
49 } 55 }
......
...@@ -3,6 +3,7 @@ package org.onlab.onos.cluster.impl; ...@@ -3,6 +3,7 @@ package org.onlab.onos.cluster.impl;
3 import static com.google.common.base.Preconditions.checkNotNull; 3 import static com.google.common.base.Preconditions.checkNotNull;
4 import static org.slf4j.LoggerFactory.getLogger; 4 import static org.slf4j.LoggerFactory.getLogger;
5 5
6 +import java.util.List;
6 import java.util.Set; 7 import java.util.Set;
7 import java.util.concurrent.atomic.AtomicInteger; 8 import java.util.concurrent.atomic.AtomicInteger;
8 9
...@@ -127,6 +128,11 @@ implements MastershipService, MastershipAdminService { ...@@ -127,6 +128,11 @@ implements MastershipService, MastershipAdminService {
127 return store.getDevices(nodeId); 128 return store.getDevices(nodeId);
128 } 129 }
129 130
131 + @Override
132 + public List<NodeId> getNodesFor(DeviceId deviceId) {
133 + checkNotNull(deviceId, DEVICE_ID_NULL);
134 + return store.getNodes(deviceId);
135 + }
130 136
131 @Override 137 @Override
132 public MastershipTermService requestTermService() { 138 public MastershipTermService requestTermService() {
......
...@@ -54,7 +54,7 @@ public class DistributedClusterStore ...@@ -54,7 +54,7 @@ public class DistributedClusterStore
54 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) 54 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
55 private ClusterCommunicationAdminService clusterCommunicationAdminService; 55 private ClusterCommunicationAdminService clusterCommunicationAdminService;
56 56
57 - private final ClusterNodesDelegate nodesDelegate = new InnerNodesDelegate(); 57 + private final ClusterNodesDelegate nodesDelegate = new InternalNodesDelegate();
58 58
59 @Activate 59 @Activate
60 public void activate() throws IOException { 60 public void activate() throws IOException {
...@@ -151,7 +151,7 @@ public class DistributedClusterStore ...@@ -151,7 +151,7 @@ public class DistributedClusterStore
151 } 151 }
152 152
153 // Entity to handle back calls from the connection manager. 153 // Entity to handle back calls from the connection manager.
154 - private class InnerNodesDelegate implements ClusterNodesDelegate { 154 + private class InternalNodesDelegate implements ClusterNodesDelegate {
155 @Override 155 @Override
156 public DefaultControllerNode nodeDetected(NodeId nodeId, IpPrefix ip, int tcpPort) { 156 public DefaultControllerNode nodeDetected(NodeId nodeId, IpPrefix ip, int tcpPort) {
157 DefaultControllerNode node = nodes.get(nodeId); 157 DefaultControllerNode node = nodes.get(nodeId);
......
...@@ -2,6 +2,8 @@ package org.onlab.onos.store.mastership.impl; ...@@ -2,6 +2,8 @@ package org.onlab.onos.store.mastership.impl;
2 2
3 import static org.onlab.onos.mastership.MastershipEvent.Type.MASTER_CHANGED; 3 import static org.onlab.onos.mastership.MastershipEvent.Type.MASTER_CHANGED;
4 4
5 +import java.util.LinkedList;
6 +import java.util.List;
5 import java.util.Map; 7 import java.util.Map;
6 import java.util.Set; 8 import java.util.Set;
7 9
...@@ -143,6 +145,30 @@ implements MastershipStore { ...@@ -143,6 +145,30 @@ implements MastershipStore {
143 return deserialize(masters.get(serialize(deviceId))); 145 return deserialize(masters.get(serialize(deviceId)));
144 } 146 }
145 147
148 +
149 + @Override
150 + public List<NodeId> getNodes(DeviceId deviceId) {
151 + byte [] did = serialize(deviceId);
152 + List<NodeId> nodes = new LinkedList<>();
153 +
154 + //add current master to head - if there is one
155 + ILock lock = theInstance.getLock(LOCK);
156 + lock.lock();
157 + try {
158 + byte [] master = masters.get(did);
159 + if (master != null) {
160 + nodes.add((NodeId) deserialize(master));
161 + }
162 +
163 + for (byte [] el : standbys.get(serialize(deviceId))) {
164 + nodes.add((NodeId) deserialize(el));
165 + }
166 + return nodes;
167 + } finally {
168 + lock.unlock();
169 + }
170 + }
171 +
146 @Override 172 @Override
147 public Set<DeviceId> getDevices(NodeId nodeId) { 173 public Set<DeviceId> getDevices(NodeId nodeId) {
148 ImmutableSet.Builder<DeviceId> builder = ImmutableSet.builder(); 174 ImmutableSet.Builder<DeviceId> builder = ImmutableSet.builder();
......
...@@ -5,6 +5,7 @@ import static org.slf4j.LoggerFactory.getLogger; ...@@ -5,6 +5,7 @@ import static org.slf4j.LoggerFactory.getLogger;
5 import java.util.Collections; 5 import java.util.Collections;
6 import java.util.HashMap; 6 import java.util.HashMap;
7 import java.util.HashSet; 7 import java.util.HashSet;
8 +import java.util.List;
8 import java.util.Map; 9 import java.util.Map;
9 import java.util.Set; 10 import java.util.Set;
10 import java.util.concurrent.atomic.AtomicInteger; 11 import java.util.concurrent.atomic.AtomicInteger;
...@@ -95,6 +96,11 @@ public class SimpleMastershipStore ...@@ -95,6 +96,11 @@ public class SimpleMastershipStore
95 } 96 }
96 97
97 @Override 98 @Override
99 + public List<NodeId> getNodes(DeviceId deviceId) {
100 + return null;
101 + }
102 +
103 + @Override
98 public Set<DeviceId> getDevices(NodeId nodeId) { 104 public Set<DeviceId> getDevices(NodeId nodeId) {
99 Set<DeviceId> ids = new HashSet<>(); 105 Set<DeviceId> ids = new HashSet<>();
100 for (Map.Entry<DeviceId, NodeId> d : masterMap.entrySet()) { 106 for (Map.Entry<DeviceId, NodeId> d : masterMap.entrySet()) {
......