Madan Jampani
Committed by Gerrit Code Review

Use mastershipService instead of replicaInfoService to determine device mastership

Change-Id: I9d07351bbd024e02b2b116dc011a8eac2f79cda1
...@@ -26,6 +26,8 @@ import org.apache.felix.scr.annotations.Service; ...@@ -26,6 +26,8 @@ import org.apache.felix.scr.annotations.Service;
26 import org.onlab.util.KryoNamespace; 26 import org.onlab.util.KryoNamespace;
27 import org.onlab.util.Tools; 27 import org.onlab.util.Tools;
28 import org.onosproject.cluster.ClusterService; 28 import org.onosproject.cluster.ClusterService;
29 +import org.onosproject.cluster.NodeId;
30 +import org.onosproject.mastership.MastershipService;
29 import org.onosproject.net.ConnectPoint; 31 import org.onosproject.net.ConnectPoint;
30 import org.onosproject.net.DeviceId; 32 import org.onosproject.net.DeviceId;
31 import org.onosproject.net.PortNumber; 33 import org.onosproject.net.PortNumber;
...@@ -37,8 +39,6 @@ import org.onosproject.net.statistic.StatisticStore; ...@@ -37,8 +39,6 @@ import org.onosproject.net.statistic.StatisticStore;
37 import org.onosproject.store.cluster.messaging.ClusterCommunicationService; 39 import org.onosproject.store.cluster.messaging.ClusterCommunicationService;
38 import org.onosproject.store.cluster.messaging.ClusterMessage; 40 import org.onosproject.store.cluster.messaging.ClusterMessage;
39 import org.onosproject.store.cluster.messaging.ClusterMessageHandler; 41 import org.onosproject.store.cluster.messaging.ClusterMessageHandler;
40 -import org.onosproject.store.flow.ReplicaInfo;
41 -import org.onosproject.store.flow.ReplicaInfoService;
42 import org.onosproject.store.serializers.KryoNamespaces; 42 import org.onosproject.store.serializers.KryoNamespaces;
43 import org.onosproject.store.serializers.KryoSerializer; 43 import org.onosproject.store.serializers.KryoSerializer;
44 import org.slf4j.Logger; 44 import org.slf4j.Logger;
...@@ -73,7 +73,7 @@ public class DistributedStatisticStore implements StatisticStore { ...@@ -73,7 +73,7 @@ public class DistributedStatisticStore implements StatisticStore {
73 private static final int MESSAGE_HANDLER_THREAD_POOL_SIZE = 4; 73 private static final int MESSAGE_HANDLER_THREAD_POOL_SIZE = 4;
74 74
75 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) 75 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
76 - protected ReplicaInfoService replicaInfoManager; 76 + protected MastershipService mastershipService;
77 77
78 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) 78 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
79 protected ClusterCommunicationService clusterCommunicator; 79 protected ClusterCommunicationService clusterCommunicator;
...@@ -200,12 +200,12 @@ public class DistributedStatisticStore implements StatisticStore { ...@@ -200,12 +200,12 @@ public class DistributedStatisticStore implements StatisticStore {
200 @Override 200 @Override
201 public Set<FlowEntry> getCurrentStatistic(ConnectPoint connectPoint) { 201 public Set<FlowEntry> getCurrentStatistic(ConnectPoint connectPoint) {
202 final DeviceId deviceId = connectPoint.deviceId(); 202 final DeviceId deviceId = connectPoint.deviceId();
203 - ReplicaInfo replicaInfo = replicaInfoManager.getReplicaInfoFor(deviceId); 203 + NodeId master = mastershipService.getMasterFor(deviceId);
204 - if (!replicaInfo.master().isPresent()) { 204 + if (master == null) {
205 log.warn("No master for {}", deviceId); 205 log.warn("No master for {}", deviceId);
206 return Collections.emptySet(); 206 return Collections.emptySet();
207 } 207 }
208 - if (replicaInfo.master().get().equals(clusterService.getLocalNode().id())) { 208 + if (master.equals(clusterService.getLocalNode().id())) {
209 return getCurrentStatisticInternal(connectPoint); 209 return getCurrentStatisticInternal(connectPoint);
210 } else { 210 } else {
211 return Tools.futureGetOrElse(clusterCommunicator.sendAndReceive( 211 return Tools.futureGetOrElse(clusterCommunicator.sendAndReceive(
...@@ -213,7 +213,7 @@ public class DistributedStatisticStore implements StatisticStore { ...@@ -213,7 +213,7 @@ public class DistributedStatisticStore implements StatisticStore {
213 GET_CURRENT, 213 GET_CURRENT,
214 SERIALIZER::encode, 214 SERIALIZER::encode,
215 SERIALIZER::decode, 215 SERIALIZER::decode,
216 - replicaInfo.master().get()), 216 + master),
217 STATISTIC_STORE_TIMEOUT_MILLIS, 217 STATISTIC_STORE_TIMEOUT_MILLIS,
218 TimeUnit.MILLISECONDS, 218 TimeUnit.MILLISECONDS,
219 Collections.emptySet()); 219 Collections.emptySet());
...@@ -228,12 +228,12 @@ public class DistributedStatisticStore implements StatisticStore { ...@@ -228,12 +228,12 @@ public class DistributedStatisticStore implements StatisticStore {
228 @Override 228 @Override
229 public Set<FlowEntry> getPreviousStatistic(ConnectPoint connectPoint) { 229 public Set<FlowEntry> getPreviousStatistic(ConnectPoint connectPoint) {
230 final DeviceId deviceId = connectPoint.deviceId(); 230 final DeviceId deviceId = connectPoint.deviceId();
231 - ReplicaInfo replicaInfo = replicaInfoManager.getReplicaInfoFor(deviceId); 231 + NodeId master = mastershipService.getMasterFor(deviceId);
232 - if (!replicaInfo.master().isPresent()) { 232 + if (master == null) {
233 log.warn("No master for {}", deviceId); 233 log.warn("No master for {}", deviceId);
234 return Collections.emptySet(); 234 return Collections.emptySet();
235 } 235 }
236 - if (replicaInfo.master().get().equals(clusterService.getLocalNode().id())) { 236 + if (master.equals(clusterService.getLocalNode().id())) {
237 return getPreviousStatisticInternal(connectPoint); 237 return getPreviousStatisticInternal(connectPoint);
238 } else { 238 } else {
239 return Tools.futureGetOrElse(clusterCommunicator.sendAndReceive( 239 return Tools.futureGetOrElse(clusterCommunicator.sendAndReceive(
...@@ -241,7 +241,7 @@ public class DistributedStatisticStore implements StatisticStore { ...@@ -241,7 +241,7 @@ public class DistributedStatisticStore implements StatisticStore {
241 GET_PREVIOUS, 241 GET_PREVIOUS,
242 SERIALIZER::encode, 242 SERIALIZER::encode,
243 SERIALIZER::decode, 243 SERIALIZER::decode,
244 - replicaInfo.master().get()), 244 + master),
245 STATISTIC_STORE_TIMEOUT_MILLIS, 245 STATISTIC_STORE_TIMEOUT_MILLIS,
246 TimeUnit.MILLISECONDS, 246 TimeUnit.MILLISECONDS,
247 Collections.emptySet()); 247 Collections.emptySet());
......
...@@ -24,6 +24,7 @@ import org.apache.felix.scr.annotations.ReferenceCardinality; ...@@ -24,6 +24,7 @@ import org.apache.felix.scr.annotations.ReferenceCardinality;
24 import org.apache.felix.scr.annotations.Service; 24 import org.apache.felix.scr.annotations.Service;
25 import org.onlab.util.KryoNamespace; 25 import org.onlab.util.KryoNamespace;
26 import org.onosproject.cluster.ClusterService; 26 import org.onosproject.cluster.ClusterService;
27 +import org.onosproject.cluster.NodeId;
27 import org.onosproject.incubator.net.resource.label.DefaultLabelResource; 28 import org.onosproject.incubator.net.resource.label.DefaultLabelResource;
28 import org.onosproject.incubator.net.resource.label.LabelResource; 29 import org.onosproject.incubator.net.resource.label.LabelResource;
29 import org.onosproject.incubator.net.resource.label.LabelResourceDelegate; 30 import org.onosproject.incubator.net.resource.label.LabelResourceDelegate;
...@@ -33,6 +34,7 @@ import org.onosproject.incubator.net.resource.label.LabelResourceId; ...@@ -33,6 +34,7 @@ import org.onosproject.incubator.net.resource.label.LabelResourceId;
33 import org.onosproject.incubator.net.resource.label.LabelResourcePool; 34 import org.onosproject.incubator.net.resource.label.LabelResourcePool;
34 import org.onosproject.incubator.net.resource.label.LabelResourceRequest; 35 import org.onosproject.incubator.net.resource.label.LabelResourceRequest;
35 import org.onosproject.incubator.net.resource.label.LabelResourceStore; 36 import org.onosproject.incubator.net.resource.label.LabelResourceStore;
37 +import org.onosproject.mastership.MastershipService;
36 import org.onosproject.net.Device; 38 import org.onosproject.net.Device;
37 import org.onosproject.net.DeviceId; 39 import org.onosproject.net.DeviceId;
38 import org.onosproject.net.device.DeviceService; 40 import org.onosproject.net.device.DeviceService;
...@@ -40,8 +42,6 @@ import org.onosproject.store.AbstractStore; ...@@ -40,8 +42,6 @@ import org.onosproject.store.AbstractStore;
40 import org.onosproject.store.cluster.messaging.ClusterCommunicationService; 42 import org.onosproject.store.cluster.messaging.ClusterCommunicationService;
41 import org.onosproject.store.cluster.messaging.ClusterMessage; 43 import org.onosproject.store.cluster.messaging.ClusterMessage;
42 import org.onosproject.store.cluster.messaging.ClusterMessageHandler; 44 import org.onosproject.store.cluster.messaging.ClusterMessageHandler;
43 -import org.onosproject.store.flow.ReplicaInfo;
44 -import org.onosproject.store.flow.ReplicaInfoService;
45 import org.onosproject.store.serializers.KryoNamespaces; 45 import org.onosproject.store.serializers.KryoNamespaces;
46 import org.onosproject.store.service.ConsistentMap; 46 import org.onosproject.store.service.ConsistentMap;
47 import org.onosproject.store.service.Serializer; 47 import org.onosproject.store.service.Serializer;
...@@ -72,7 +72,7 @@ public class DistributedLabelResourceStore ...@@ -72,7 +72,7 @@ public class DistributedLabelResourceStore
72 protected StorageService storageService; 72 protected StorageService storageService;
73 73
74 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) 74 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
75 - protected ReplicaInfoService replicaInfoManager; 75 + protected MastershipService mastershipService;
76 76
77 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) 77 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
78 protected ClusterCommunicationService clusterCommunicator; 78 protected ClusterCommunicationService clusterCommunicator;
...@@ -210,27 +210,25 @@ public class DistributedLabelResourceStore ...@@ -210,27 +210,25 @@ public class DistributedLabelResourceStore
210 return false; 210 return false;
211 } 211 }
212 212
213 - ReplicaInfo replicaInfo = replicaInfoManager.getReplicaInfoFor(pool 213 + NodeId master = mastershipService.getMasterFor(pool.deviceId());
214 - .deviceId());
215 214
216 - if (!replicaInfo.master().isPresent()) { 215 + if (master == null) {
217 - log.warn("Failed to getFlowEntries: No master for {}", pool); 216 + log.warn("Failed to create label resource pool: No master for {}", pool);
218 return false; 217 return false;
219 } 218 }
220 219
221 - if (replicaInfo.master().get() 220 + if (master.equals(clusterService.getLocalNode().id())) {
222 - .equals(clusterService.getLocalNode().id())) {
223 return internalCreate(pool); 221 return internalCreate(pool);
224 } 222 }
225 223
226 log.trace("Forwarding getFlowEntries to {}, which is the primary (master) for device {}", 224 log.trace("Forwarding getFlowEntries to {}, which is the primary (master) for device {}",
227 - replicaInfo.master().orNull(), pool.deviceId()); 225 + master, pool.deviceId());
228 226
229 return complete(clusterCommunicator 227 return complete(clusterCommunicator
230 .sendAndReceive(pool, 228 .sendAndReceive(pool,
231 LabelResourceMessageSubjects.LABEL_POOL_CREATED, 229 LabelResourceMessageSubjects.LABEL_POOL_CREATED,
232 SERIALIZER::encode, SERIALIZER::decode, 230 SERIALIZER::encode, SERIALIZER::decode,
233 - replicaInfo.master().get())); 231 + master));
234 } 232 }
235 233
236 private boolean internalCreate(LabelResourcePool pool) { 234 private boolean internalCreate(LabelResourcePool pool) {
...@@ -253,27 +251,26 @@ public class DistributedLabelResourceStore ...@@ -253,27 +251,26 @@ public class DistributedLabelResourceStore
253 if (device == null) { 251 if (device == null) {
254 return false; 252 return false;
255 } 253 }
256 - ReplicaInfo replicaInfo = replicaInfoManager
257 - .getReplicaInfoFor(deviceId);
258 254
259 - if (!replicaInfo.master().isPresent()) { 255 + NodeId master = mastershipService.getMasterFor(deviceId);
260 - log.warn("Failed to getFlowEntries: No master for {}", deviceId); 256 +
257 + if (master == null) {
258 + log.warn("Failed to destroyDevicePool. No master for {}", deviceId);
261 return false; 259 return false;
262 } 260 }
263 261
264 - if (replicaInfo.master().get() 262 + if (master.equals(clusterService.getLocalNode().id())) {
265 - .equals(clusterService.getLocalNode().id())) {
266 return internalDestroy(deviceId); 263 return internalDestroy(deviceId);
267 } 264 }
268 265
269 - log.trace("Forwarding getFlowEntries to {}, which is the primary (master) for device {}", 266 + log.trace("Forwarding request to {}, which is the primary (master) for device {}",
270 - replicaInfo.master().orNull(), deviceId); 267 + master, deviceId);
271 268
272 return complete(clusterCommunicator 269 return complete(clusterCommunicator
273 .sendAndReceive(deviceId, 270 .sendAndReceive(deviceId,
274 LabelResourceMessageSubjects.LABEL_POOL_DESTROYED, 271 LabelResourceMessageSubjects.LABEL_POOL_DESTROYED,
275 SERIALIZER::encode, SERIALIZER::decode, 272 SERIALIZER::encode, SERIALIZER::decode,
276 - replicaInfo.master().get())); 273 + master));
277 } 274 }
278 275
279 private boolean internalDestroy(DeviceId deviceId) { 276 private boolean internalDestroy(DeviceId deviceId) {
...@@ -301,27 +298,25 @@ public class DistributedLabelResourceStore ...@@ -301,27 +298,25 @@ public class DistributedLabelResourceStore
301 deviceId, 298 deviceId,
302 LabelResourceRequest.Type.APPLY, 299 LabelResourceRequest.Type.APPLY,
303 applyNum, null); 300 applyNum, null);
304 - ReplicaInfo replicaInfo = replicaInfoManager 301 + NodeId master = mastershipService.getMasterFor(deviceId);
305 - .getReplicaInfoFor(deviceId);
306 302
307 - if (!replicaInfo.master().isPresent()) { 303 + if (master == null) {
308 - log.warn("Failed to getFlowEntries: No master for {}", deviceId); 304 + log.warn("Failed to applyFromDevicePool: No master for {}", deviceId);
309 return Collections.emptyList(); 305 return Collections.emptyList();
310 } 306 }
311 307
312 - if (replicaInfo.master().get() 308 + if (master.equals(clusterService.getLocalNode().id())) {
313 - .equals(clusterService.getLocalNode().id())) {
314 return internalApply(request); 309 return internalApply(request);
315 } 310 }
316 311
317 - log.trace("Forwarding getFlowEntries to {}, which is the primary (master) for device {}", 312 + log.trace("Forwarding request to {}, which is the primary (master) for device {}",
318 - replicaInfo.master().orNull(), deviceId); 313 + master, deviceId);
319 314
320 return complete(clusterCommunicator 315 return complete(clusterCommunicator
321 .sendAndReceive(request, 316 .sendAndReceive(request,
322 LabelResourceMessageSubjects.LABEL_POOL_APPLY, 317 LabelResourceMessageSubjects.LABEL_POOL_APPLY,
323 SERIALIZER::encode, SERIALIZER::decode, 318 SERIALIZER::encode, SERIALIZER::decode,
324 - replicaInfo.master().get())); 319 + master));
325 } 320 }
326 321
327 private Collection<LabelResource> internalApply(LabelResourceRequest request) { 322 private Collection<LabelResource> internalApply(LabelResourceRequest request) {
...@@ -388,27 +383,25 @@ public class DistributedLabelResourceStore ...@@ -388,27 +383,25 @@ public class DistributedLabelResourceStore
388 deviceId, 383 deviceId,
389 LabelResourceRequest.Type.RELEASE, 384 LabelResourceRequest.Type.RELEASE,
390 0, collection); 385 0, collection);
391 - ReplicaInfo replicaInfo = replicaInfoManager 386 + NodeId master = mastershipService.getMasterFor(deviceId);
392 - .getReplicaInfoFor(deviceId);
393 387
394 - if (!replicaInfo.master().isPresent()) { 388 + if (master == null) {
395 - log.warn("Failed to getFlowEntries: No master for {}", deviceId); 389 + log.warn("Failed to releaseToDevicePool: No master for {}", deviceId);
396 return false; 390 return false;
397 } 391 }
398 392
399 - if (replicaInfo.master().get() 393 + if (master.equals(clusterService.getLocalNode().id())) {
400 - .equals(clusterService.getLocalNode().id())) {
401 return internalRelease(request); 394 return internalRelease(request);
402 } 395 }
403 396
404 - log.trace("Forwarding getFlowEntries to {}, which is the primary (master) for device {}", 397 + log.trace("Forwarding request to {}, which is the primary (master) for device {}",
405 - replicaInfo.master().orNull(), deviceId); 398 + master, deviceId);
406 399
407 return complete(clusterCommunicator 400 return complete(clusterCommunicator
408 .sendAndReceive(request, 401 .sendAndReceive(request,
409 LabelResourceMessageSubjects.LABEL_POOL_RELEASE, 402 LabelResourceMessageSubjects.LABEL_POOL_RELEASE,
410 SERIALIZER::encode, SERIALIZER::decode, 403 SERIALIZER::encode, SERIALIZER::decode,
411 - replicaInfo.master().get())); 404 + master));
412 } 405 }
413 return false; 406 return false;
414 } 407 }
......