Committed by
Pavlin Radoslavov
LeadershipService API change: Using NodeId in place of ControllerNode.
Change-Id: I6f688506c3672977456fc6921b26e98be2239632
Showing
8 changed files
with
55 additions
and
56 deletions
... | @@ -167,7 +167,7 @@ public class SdnIp implements SdnIpService { | ... | @@ -167,7 +167,7 @@ public class SdnIp implements SdnIpService { |
167 | if (!event.subject().topic().equals(appId.name())) { | 167 | if (!event.subject().topic().equals(appId.name())) { |
168 | return; // Not our topic: ignore | 168 | return; // Not our topic: ignore |
169 | } | 169 | } |
170 | - if (!event.subject().leader().id().equals( | 170 | + if (!event.subject().leader().equals( |
171 | localControllerNode.id())) { | 171 | localControllerNode.id())) { |
172 | return; // The event is not about this instance: ignore | 172 | return; // The event is not about this instance: ignore |
173 | } | 173 | } | ... | ... |
... | @@ -37,7 +37,7 @@ public class LeaderCommand extends AbstractShellCommand { | ... | @@ -37,7 +37,7 @@ public class LeaderCommand extends AbstractShellCommand { |
37 | Map<String, Leadership> leaderBoard = leaderService.getLeaderBoard(); | 37 | Map<String, Leadership> leaderBoard = leaderService.getLeaderBoard(); |
38 | print(FMT, "Topic", "Leader"); | 38 | print(FMT, "Topic", "Leader"); |
39 | for (String topic : leaderBoard.keySet()) { | 39 | for (String topic : leaderBoard.keySet()) { |
40 | - print(FMT, topic, leaderBoard.get(topic).leader().id()); | 40 | + print(FMT, topic, leaderBoard.get(topic).leader()); |
41 | } | 41 | } |
42 | } | 42 | } |
43 | 43 | ... | ... |
... | @@ -10,10 +10,10 @@ import com.google.common.base.MoreObjects; | ... | @@ -10,10 +10,10 @@ import com.google.common.base.MoreObjects; |
10 | public class Leadership { | 10 | public class Leadership { |
11 | 11 | ||
12 | private final String topic; | 12 | private final String topic; |
13 | - private final ControllerNode leader; | 13 | + private final NodeId leader; |
14 | private final long epoch; | 14 | private final long epoch; |
15 | 15 | ||
16 | - public Leadership(String topic, ControllerNode leader, long epoch) { | 16 | + public Leadership(String topic, NodeId leader, long epoch) { |
17 | this.topic = topic; | 17 | this.topic = topic; |
18 | this.leader = leader; | 18 | this.leader = leader; |
19 | this.epoch = epoch; | 19 | this.epoch = epoch; |
... | @@ -28,10 +28,10 @@ public class Leadership { | ... | @@ -28,10 +28,10 @@ public class Leadership { |
28 | } | 28 | } |
29 | 29 | ||
30 | /** | 30 | /** |
31 | - * The leader for this topic. | 31 | + * The nodeId of leader for this topic. |
32 | * @return leader node. | 32 | * @return leader node. |
33 | */ | 33 | */ |
34 | - public ControllerNode leader() { | 34 | + public NodeId leader() { |
35 | return leader; | 35 | return leader; |
36 | } | 36 | } |
37 | 37 | ... | ... |
... | @@ -29,9 +29,9 @@ public interface LeadershipService { | ... | @@ -29,9 +29,9 @@ public interface LeadershipService { |
29 | /** | 29 | /** |
30 | * Gets the most recent leader for the topic. | 30 | * Gets the most recent leader for the topic. |
31 | * @param path topic | 31 | * @param path topic |
32 | - * @return node who is the leader, null if so such topic exists. | 32 | + * @return nodeId of the leader, null if so such topic exists. |
33 | */ | 33 | */ |
34 | - ControllerNode getLeader(String path); | 34 | + NodeId getLeader(String path); |
35 | 35 | ||
36 | /** | 36 | /** |
37 | * Joins the leadership contest. | 37 | * Joins the leadership contest. | ... | ... |
... | @@ -31,7 +31,6 @@ import org.apache.felix.scr.annotations.Reference; | ... | @@ -31,7 +31,6 @@ import org.apache.felix.scr.annotations.Reference; |
31 | import org.apache.felix.scr.annotations.ReferenceCardinality; | 31 | import org.apache.felix.scr.annotations.ReferenceCardinality; |
32 | import org.apache.felix.scr.annotations.Service; | 32 | import org.apache.felix.scr.annotations.Service; |
33 | import org.onlab.onos.cluster.ClusterService; | 33 | import org.onlab.onos.cluster.ClusterService; |
34 | -import org.onlab.onos.cluster.ControllerNode; | ||
35 | import org.onlab.onos.cluster.Leadership; | 34 | import org.onlab.onos.cluster.Leadership; |
36 | import org.onlab.onos.cluster.LeadershipEvent; | 35 | import org.onlab.onos.cluster.LeadershipEvent; |
37 | import org.onlab.onos.cluster.LeadershipEventListener; | 36 | import org.onlab.onos.cluster.LeadershipEventListener; |
... | @@ -100,11 +99,11 @@ public class HazelcastLeadershipService implements LeadershipService { | ... | @@ -100,11 +99,11 @@ public class HazelcastLeadershipService implements LeadershipService { |
100 | private AbstractListenerRegistry<LeadershipEvent, LeadershipEventListener> | 99 | private AbstractListenerRegistry<LeadershipEvent, LeadershipEventListener> |
101 | listenerRegistry; | 100 | listenerRegistry; |
102 | private final Map<String, Topic> topics = Maps.newConcurrentMap(); | 101 | private final Map<String, Topic> topics = Maps.newConcurrentMap(); |
103 | - private ControllerNode localNode; | 102 | + private NodeId localNodeId; |
104 | 103 | ||
105 | @Activate | 104 | @Activate |
106 | protected void activate() { | 105 | protected void activate() { |
107 | - localNode = clusterService.getLocalNode(); | 106 | + localNodeId = clusterService.getLocalNode().id(); |
108 | listenerRegistry = new AbstractListenerRegistry<>(); | 107 | listenerRegistry = new AbstractListenerRegistry<>(); |
109 | eventDispatcher.addSink(LeadershipEvent.class, listenerRegistry); | 108 | eventDispatcher.addSink(LeadershipEvent.class, listenerRegistry); |
110 | 109 | ||
... | @@ -124,7 +123,7 @@ public class HazelcastLeadershipService implements LeadershipService { | ... | @@ -124,7 +123,7 @@ public class HazelcastLeadershipService implements LeadershipService { |
124 | } | 123 | } |
125 | 124 | ||
126 | @Override | 125 | @Override |
127 | - public ControllerNode getLeader(String path) { | 126 | + public NodeId getLeader(String path) { |
128 | Topic topic = topics.get(path); | 127 | Topic topic = topics.get(path); |
129 | if (topic == null) { | 128 | if (topic == null) { |
130 | return null; | 129 | return null; |
... | @@ -177,7 +176,7 @@ public class HazelcastLeadershipService implements LeadershipService { | ... | @@ -177,7 +176,7 @@ public class HazelcastLeadershipService implements LeadershipService { |
177 | private volatile long lastLeadershipUpdateMs = 0; | 176 | private volatile long lastLeadershipUpdateMs = 0; |
178 | private ExecutorService leaderElectionExecutor; | 177 | private ExecutorService leaderElectionExecutor; |
179 | 178 | ||
180 | - private ControllerNode leader; | 179 | + private NodeId leader; |
181 | private Lock leaderLock; | 180 | private Lock leaderLock; |
182 | private Future<?> getLockFuture; | 181 | private Future<?> getLockFuture; |
183 | private Future<?> periodicProcessingFuture; | 182 | private Future<?> periodicProcessingFuture; |
... | @@ -198,7 +197,7 @@ public class HazelcastLeadershipService implements LeadershipService { | ... | @@ -198,7 +197,7 @@ public class HazelcastLeadershipService implements LeadershipService { |
198 | * | 197 | * |
199 | * @return the leader for the topic | 198 | * @return the leader for the topic |
200 | */ | 199 | */ |
201 | - private ControllerNode leader() { | 200 | + private NodeId leader() { |
202 | return leader; | 201 | return leader; |
203 | } | 202 | } |
204 | 203 | ||
... | @@ -254,7 +253,7 @@ public class HazelcastLeadershipService implements LeadershipService { | ... | @@ -254,7 +253,7 @@ public class HazelcastLeadershipService implements LeadershipService { |
254 | public void onMessage(Message<byte[]> message) { | 253 | public void onMessage(Message<byte[]> message) { |
255 | LeadershipEvent leadershipEvent = | 254 | LeadershipEvent leadershipEvent = |
256 | SERIALIZER.decode(message.getMessageObject()); | 255 | SERIALIZER.decode(message.getMessageObject()); |
257 | - NodeId eventLeaderId = leadershipEvent.subject().leader().id(); | 256 | + NodeId eventLeaderId = leadershipEvent.subject().leader(); |
258 | 257 | ||
259 | log.debug("Leadership Event: time = {} type = {} event = {}", | 258 | log.debug("Leadership Event: time = {} type = {} event = {}", |
260 | leadershipEvent.time(), leadershipEvent.type(), | 259 | leadershipEvent.time(), leadershipEvent.type(), |
... | @@ -262,7 +261,7 @@ public class HazelcastLeadershipService implements LeadershipService { | ... | @@ -262,7 +261,7 @@ public class HazelcastLeadershipService implements LeadershipService { |
262 | if (!leadershipEvent.subject().topic().equals(topicName)) { | 261 | if (!leadershipEvent.subject().topic().equals(topicName)) { |
263 | return; // Not our topic: ignore | 262 | return; // Not our topic: ignore |
264 | } | 263 | } |
265 | - if (eventLeaderId.equals(localNode.id())) { | 264 | + if (eventLeaderId.equals(localNodeId)) { |
266 | return; // My own message: ignore | 265 | return; // My own message: ignore |
267 | } | 266 | } |
268 | 267 | ||
... | @@ -276,7 +275,7 @@ public class HazelcastLeadershipService implements LeadershipService { | ... | @@ -276,7 +275,7 @@ public class HazelcastLeadershipService implements LeadershipService { |
276 | // leadership and run for re-election. | 275 | // leadership and run for re-election. |
277 | // | 276 | // |
278 | if ((leader != null) && | 277 | if ((leader != null) && |
279 | - leader.id().equals(localNode.id())) { | 278 | + leader.equals(localNodeId)) { |
280 | getLockFuture.cancel(true); | 279 | getLockFuture.cancel(true); |
281 | } else { | 280 | } else { |
282 | // Just update the current leader | 281 | // Just update the current leader |
... | @@ -288,7 +287,7 @@ public class HazelcastLeadershipService implements LeadershipService { | ... | @@ -288,7 +287,7 @@ public class HazelcastLeadershipService implements LeadershipService { |
288 | case LEADER_BOOTED: | 287 | case LEADER_BOOTED: |
289 | // Remove the state for the current leader | 288 | // Remove the state for the current leader |
290 | if ((leader != null) && | 289 | if ((leader != null) && |
291 | - eventLeaderId.equals(leader.id())) { | 290 | + eventLeaderId.equals(leader)) { |
292 | leader = null; | 291 | leader = null; |
293 | } | 292 | } |
294 | eventDispatcher.post(leadershipEvent); | 293 | eventDispatcher.post(leadershipEvent); |
... | @@ -312,13 +311,13 @@ public class HazelcastLeadershipService implements LeadershipService { | ... | @@ -312,13 +311,13 @@ public class HazelcastLeadershipService implements LeadershipService { |
312 | synchronized (this) { | 311 | synchronized (this) { |
313 | LeadershipEvent leadershipEvent; | 312 | LeadershipEvent leadershipEvent; |
314 | if (leader != null) { | 313 | if (leader != null) { |
315 | - if (leader.id().equals(localNode.id())) { | 314 | + if (leader.equals(localNodeId)) { |
316 | // | 315 | // |
317 | // Advertise ourselves as the leader | 316 | // Advertise ourselves as the leader |
318 | // | 317 | // |
319 | leadershipEvent = new LeadershipEvent( | 318 | leadershipEvent = new LeadershipEvent( |
320 | LeadershipEvent.Type.LEADER_REELECTED, | 319 | LeadershipEvent.Type.LEADER_REELECTED, |
321 | - new Leadership(topicName, localNode, 0)); | 320 | + new Leadership(topicName, localNodeId, 0)); |
322 | // Dispatch to all remote instances | 321 | // Dispatch to all remote instances |
323 | leaderTopic.publish(SERIALIZER.encode(leadershipEvent)); | 322 | leaderTopic.publish(SERIALIZER.encode(leadershipEvent)); |
324 | } else { | 323 | } else { |
... | @@ -379,10 +378,10 @@ public class HazelcastLeadershipService implements LeadershipService { | ... | @@ -379,10 +378,10 @@ public class HazelcastLeadershipService implements LeadershipService { |
379 | // This instance is now the leader | 378 | // This instance is now the leader |
380 | // | 379 | // |
381 | log.info("Leader Elected for topic {}", topicName); | 380 | log.info("Leader Elected for topic {}", topicName); |
382 | - leader = localNode; | 381 | + leader = localNodeId; |
383 | leadershipEvent = new LeadershipEvent( | 382 | leadershipEvent = new LeadershipEvent( |
384 | LeadershipEvent.Type.LEADER_ELECTED, | 383 | LeadershipEvent.Type.LEADER_ELECTED, |
385 | - new Leadership(topicName, localNode, 0)); | 384 | + new Leadership(topicName, localNodeId, 0)); |
386 | eventDispatcher.post(leadershipEvent); | 385 | eventDispatcher.post(leadershipEvent); |
387 | leaderTopic.publish(SERIALIZER.encode(leadershipEvent)); | 386 | leaderTopic.publish(SERIALIZER.encode(leadershipEvent)); |
388 | } | 387 | } |
... | @@ -403,12 +402,12 @@ public class HazelcastLeadershipService implements LeadershipService { | ... | @@ -403,12 +402,12 @@ public class HazelcastLeadershipService implements LeadershipService { |
403 | // If we reach here, we should release the leadership | 402 | // If we reach here, we should release the leadership |
404 | log.debug("Leader Lock Released for topic {}", topicName); | 403 | log.debug("Leader Lock Released for topic {}", topicName); |
405 | if ((leader != null) && | 404 | if ((leader != null) && |
406 | - leader.id().equals(localNode.id())) { | 405 | + leader.equals(localNodeId)) { |
407 | leader = null; | 406 | leader = null; |
408 | } | 407 | } |
409 | leadershipEvent = new LeadershipEvent( | 408 | leadershipEvent = new LeadershipEvent( |
410 | LeadershipEvent.Type.LEADER_BOOTED, | 409 | LeadershipEvent.Type.LEADER_BOOTED, |
411 | - new Leadership(topicName, localNode, 0)); | 410 | + new Leadership(topicName, localNodeId, 0)); |
412 | eventDispatcher.post(leadershipEvent); | 411 | eventDispatcher.post(leadershipEvent); |
413 | leaderTopic.publish(SERIALIZER.encode(leadershipEvent)); | 412 | leaderTopic.publish(SERIALIZER.encode(leadershipEvent)); |
414 | leaderLock.unlock(); | 413 | leaderLock.unlock(); | ... | ... |
... | @@ -11,7 +11,6 @@ import java.util.concurrent.Executors; | ... | @@ -11,7 +11,6 @@ import java.util.concurrent.Executors; |
11 | import java.util.concurrent.ScheduledExecutorService; | 11 | import java.util.concurrent.ScheduledExecutorService; |
12 | import java.util.concurrent.TimeUnit; | 12 | import java.util.concurrent.TimeUnit; |
13 | 13 | ||
14 | -import com.google.common.collect.ImmutableMap; | ||
15 | import org.apache.felix.scr.annotations.Activate; | 14 | import org.apache.felix.scr.annotations.Activate; |
16 | import org.apache.felix.scr.annotations.Component; | 15 | import org.apache.felix.scr.annotations.Component; |
17 | import org.apache.felix.scr.annotations.Deactivate; | 16 | import org.apache.felix.scr.annotations.Deactivate; |
... | @@ -19,11 +18,11 @@ import org.apache.felix.scr.annotations.Reference; | ... | @@ -19,11 +18,11 @@ import org.apache.felix.scr.annotations.Reference; |
19 | import org.apache.felix.scr.annotations.ReferenceCardinality; | 18 | import org.apache.felix.scr.annotations.ReferenceCardinality; |
20 | import org.apache.felix.scr.annotations.Service; | 19 | import org.apache.felix.scr.annotations.Service; |
21 | import org.onlab.onos.cluster.ClusterService; | 20 | import org.onlab.onos.cluster.ClusterService; |
22 | -import org.onlab.onos.cluster.ControllerNode; | ||
23 | import org.onlab.onos.cluster.Leadership; | 21 | import org.onlab.onos.cluster.Leadership; |
24 | import org.onlab.onos.cluster.LeadershipEvent; | 22 | import org.onlab.onos.cluster.LeadershipEvent; |
25 | import org.onlab.onos.cluster.LeadershipEventListener; | 23 | import org.onlab.onos.cluster.LeadershipEventListener; |
26 | import org.onlab.onos.cluster.LeadershipService; | 24 | import org.onlab.onos.cluster.LeadershipService; |
25 | +import org.onlab.onos.cluster.NodeId; | ||
27 | import org.onlab.onos.store.cluster.messaging.ClusterCommunicationService; | 26 | import org.onlab.onos.store.cluster.messaging.ClusterCommunicationService; |
28 | import org.onlab.onos.store.cluster.messaging.ClusterMessage; | 27 | import org.onlab.onos.store.cluster.messaging.ClusterMessage; |
29 | import org.onlab.onos.store.cluster.messaging.ClusterMessageHandler; | 28 | import org.onlab.onos.store.cluster.messaging.ClusterMessageHandler; |
... | @@ -36,6 +35,7 @@ import org.onlab.onos.store.service.impl.DistributedLockManager; | ... | @@ -36,6 +35,7 @@ import org.onlab.onos.store.service.impl.DistributedLockManager; |
36 | import org.onlab.util.KryoNamespace; | 35 | import org.onlab.util.KryoNamespace; |
37 | import org.slf4j.Logger; | 36 | import org.slf4j.Logger; |
38 | 37 | ||
38 | +import com.google.common.collect.ImmutableMap; | ||
39 | import com.google.common.collect.Maps; | 39 | import com.google.common.collect.Maps; |
40 | import com.google.common.collect.Sets; | 40 | import com.google.common.collect.Sets; |
41 | 41 | ||
... | @@ -77,7 +77,7 @@ public class LeadershipManager implements LeadershipService { | ... | @@ -77,7 +77,7 @@ public class LeadershipManager implements LeadershipService { |
77 | 77 | ||
78 | private final Map<String, Lock> openContests = Maps.newConcurrentMap(); | 78 | private final Map<String, Lock> openContests = Maps.newConcurrentMap(); |
79 | private final Set<LeadershipEventListener> listeners = Sets.newIdentityHashSet(); | 79 | private final Set<LeadershipEventListener> listeners = Sets.newIdentityHashSet(); |
80 | - private ControllerNode localNode; | 80 | + private NodeId localNodeId; |
81 | 81 | ||
82 | private final LeadershipEventListener peerAdvertiser = new PeerAdvertiser(); | 82 | private final LeadershipEventListener peerAdvertiser = new PeerAdvertiser(); |
83 | private final LeadershipEventListener leaderBoardUpdater = new LeaderBoardUpdater(); | 83 | private final LeadershipEventListener leaderBoardUpdater = new LeaderBoardUpdater(); |
... | @@ -94,7 +94,7 @@ public class LeadershipManager implements LeadershipService { | ... | @@ -94,7 +94,7 @@ public class LeadershipManager implements LeadershipService { |
94 | 94 | ||
95 | @Activate | 95 | @Activate |
96 | public void activate() { | 96 | public void activate() { |
97 | - localNode = clusterService.getLocalNode(); | 97 | + localNodeId = clusterService.getLocalNode().id(); |
98 | 98 | ||
99 | addListener(peerAdvertiser); | 99 | addListener(peerAdvertiser); |
100 | addListener(leaderBoardUpdater); | 100 | addListener(leaderBoardUpdater); |
... | @@ -120,7 +120,7 @@ public class LeadershipManager implements LeadershipService { | ... | @@ -120,7 +120,7 @@ public class LeadershipManager implements LeadershipService { |
120 | 120 | ||
121 | 121 | ||
122 | @Override | 122 | @Override |
123 | - public ControllerNode getLeader(String path) { | 123 | + public NodeId getLeader(String path) { |
124 | synchronized (leaderBoard) { | 124 | synchronized (leaderBoard) { |
125 | Leadership leadership = leaderBoard.get(path); | 125 | Leadership leadership = leaderBoard.get(path); |
126 | if (leadership != null) { | 126 | if (leadership != null) { |
... | @@ -155,7 +155,7 @@ public class LeadershipManager implements LeadershipService { | ... | @@ -155,7 +155,7 @@ public class LeadershipManager implements LeadershipService { |
155 | notifyListeners( | 155 | notifyListeners( |
156 | new LeadershipEvent( | 156 | new LeadershipEvent( |
157 | LeadershipEvent.Type.LEADER_BOOTED, | 157 | LeadershipEvent.Type.LEADER_BOOTED, |
158 | - new Leadership(lock.path(), localNode, lock.epoch()))); | 158 | + new Leadership(lock.path(), localNodeId, lock.epoch()))); |
159 | } | 159 | } |
160 | } | 160 | } |
161 | 161 | ||
... | @@ -201,7 +201,7 @@ public class LeadershipManager implements LeadershipService { | ... | @@ -201,7 +201,7 @@ public class LeadershipManager implements LeadershipService { |
201 | notifyListeners( | 201 | notifyListeners( |
202 | new LeadershipEvent( | 202 | new LeadershipEvent( |
203 | LeadershipEvent.Type.LEADER_ELECTED, | 203 | LeadershipEvent.Type.LEADER_ELECTED, |
204 | - new Leadership(lock.path(), localNode, lock.epoch()))); | 204 | + new Leadership(lock.path(), localNodeId, lock.epoch()))); |
205 | return; | 205 | return; |
206 | } else { | 206 | } else { |
207 | log.warn("Failed to acquire lock for {}. Will retry in {} ms", path, WAIT_BEFORE_RETRY_MS, error); | 207 | log.warn("Failed to acquire lock for {}. Will retry in {} ms", path, WAIT_BEFORE_RETRY_MS, error); |
... | @@ -236,7 +236,7 @@ public class LeadershipManager implements LeadershipService { | ... | @@ -236,7 +236,7 @@ public class LeadershipManager implements LeadershipService { |
236 | notifyListeners( | 236 | notifyListeners( |
237 | new LeadershipEvent( | 237 | new LeadershipEvent( |
238 | LeadershipEvent.Type.LEADER_REELECTED, | 238 | LeadershipEvent.Type.LEADER_REELECTED, |
239 | - new Leadership(lock.path(), localNode, lock.epoch()))); | 239 | + new Leadership(lock.path(), localNodeId, lock.epoch()))); |
240 | threadPool.schedule(this, TERM_DURATION_MS / 2, TimeUnit.MILLISECONDS); | 240 | threadPool.schedule(this, TERM_DURATION_MS / 2, TimeUnit.MILLISECONDS); |
241 | } else { | 241 | } else { |
242 | // Check if this node already withdrew from the contest, in which case | 242 | // Check if this node already withdrew from the contest, in which case |
... | @@ -245,7 +245,7 @@ public class LeadershipManager implements LeadershipService { | ... | @@ -245,7 +245,7 @@ public class LeadershipManager implements LeadershipService { |
245 | notifyListeners( | 245 | notifyListeners( |
246 | new LeadershipEvent( | 246 | new LeadershipEvent( |
247 | LeadershipEvent.Type.LEADER_BOOTED, | 247 | LeadershipEvent.Type.LEADER_BOOTED, |
248 | - new Leadership(lock.path(), localNode, lock.epoch()))); | 248 | + new Leadership(lock.path(), localNodeId, lock.epoch()))); |
249 | // Retry leadership after a brief wait. | 249 | // Retry leadership after a brief wait. |
250 | threadPool.schedule(new TryLeadership(lock), WAIT_BEFORE_RETRY_MS, TimeUnit.MILLISECONDS); | 250 | threadPool.schedule(new TryLeadership(lock), WAIT_BEFORE_RETRY_MS, TimeUnit.MILLISECONDS); |
251 | } | 251 | } |
... | @@ -270,11 +270,11 @@ public class LeadershipManager implements LeadershipService { | ... | @@ -270,11 +270,11 @@ public class LeadershipManager implements LeadershipService { |
270 | @Override | 270 | @Override |
271 | public void event(LeadershipEvent event) { | 271 | public void event(LeadershipEvent event) { |
272 | // publish events originating on this host. | 272 | // publish events originating on this host. |
273 | - if (event.subject().leader().equals(localNode)) { | 273 | + if (event.subject().leader().equals(localNodeId)) { |
274 | try { | 274 | try { |
275 | clusterCommunicator.broadcast( | 275 | clusterCommunicator.broadcast( |
276 | new ClusterMessage( | 276 | new ClusterMessage( |
277 | - localNode.id(), | 277 | + localNodeId, |
278 | LEADERSHIP_UPDATES, | 278 | LEADERSHIP_UPDATES, |
279 | SERIALIZER.encode(event))); | 279 | SERIALIZER.encode(event))); |
280 | } catch (IOException e) { | 280 | } catch (IOException e) { | ... | ... |
... | @@ -15,12 +15,12 @@ | ... | @@ -15,12 +15,12 @@ |
15 | */ | 15 | */ |
16 | package org.onlab.onos.store.intent.impl; | 16 | package org.onlab.onos.store.intent.impl; |
17 | 17 | ||
18 | -import com.google.common.collect.Maps; | 18 | +import static com.google.common.base.Preconditions.checkNotNull; |
19 | -import com.google.common.collect.Sets; | 19 | +import static com.google.common.base.Preconditions.checkState; |
20 | -import com.hazelcast.core.HazelcastInstance; | 20 | +import static org.slf4j.LoggerFactory.getLogger; |
21 | -import com.hazelcast.core.IQueue; | 21 | + |
22 | -import com.hazelcast.core.ItemEvent; | 22 | +import java.util.Map; |
23 | -import com.hazelcast.core.ItemListener; | 23 | +import java.util.Set; |
24 | 24 | ||
25 | import org.apache.felix.scr.annotations.Activate; | 25 | import org.apache.felix.scr.annotations.Activate; |
26 | import org.apache.felix.scr.annotations.Component; | 26 | import org.apache.felix.scr.annotations.Component; |
... | @@ -29,10 +29,10 @@ import org.apache.felix.scr.annotations.Reference; | ... | @@ -29,10 +29,10 @@ import org.apache.felix.scr.annotations.Reference; |
29 | import org.apache.felix.scr.annotations.ReferenceCardinality; | 29 | import org.apache.felix.scr.annotations.ReferenceCardinality; |
30 | import org.apache.felix.scr.annotations.Service; | 30 | import org.apache.felix.scr.annotations.Service; |
31 | import org.onlab.onos.cluster.ClusterService; | 31 | import org.onlab.onos.cluster.ClusterService; |
32 | -import org.onlab.onos.cluster.ControllerNode; | ||
33 | import org.onlab.onos.cluster.LeadershipEvent; | 32 | import org.onlab.onos.cluster.LeadershipEvent; |
34 | import org.onlab.onos.cluster.LeadershipEventListener; | 33 | import org.onlab.onos.cluster.LeadershipEventListener; |
35 | import org.onlab.onos.cluster.LeadershipService; | 34 | import org.onlab.onos.cluster.LeadershipService; |
35 | +import org.onlab.onos.cluster.NodeId; | ||
36 | import org.onlab.onos.core.ApplicationId; | 36 | import org.onlab.onos.core.ApplicationId; |
37 | import org.onlab.onos.core.CoreService; | 37 | import org.onlab.onos.core.CoreService; |
38 | import org.onlab.onos.event.AbstractListenerRegistry; | 38 | import org.onlab.onos.event.AbstractListenerRegistry; |
... | @@ -50,12 +50,12 @@ import org.onlab.onos.store.serializers.StoreSerializer; | ... | @@ -50,12 +50,12 @@ import org.onlab.onos.store.serializers.StoreSerializer; |
50 | import org.onlab.util.KryoNamespace; | 50 | import org.onlab.util.KryoNamespace; |
51 | import org.slf4j.Logger; | 51 | import org.slf4j.Logger; |
52 | 52 | ||
53 | -import java.util.Map; | 53 | +import com.google.common.collect.Maps; |
54 | -import java.util.Set; | 54 | +import com.google.common.collect.Sets; |
55 | - | 55 | +import com.hazelcast.core.HazelcastInstance; |
56 | -import static com.google.common.base.Preconditions.checkNotNull; | 56 | +import com.hazelcast.core.IQueue; |
57 | -import static com.google.common.base.Preconditions.checkState; | 57 | +import com.hazelcast.core.ItemEvent; |
58 | -import static org.slf4j.LoggerFactory.getLogger; | 58 | +import com.hazelcast.core.ItemListener; |
59 | 59 | ||
60 | @Component(immediate = true) | 60 | @Component(immediate = true) |
61 | @Service | 61 | @Service |
... | @@ -82,7 +82,7 @@ public class HazelcastIntentBatchQueue | ... | @@ -82,7 +82,7 @@ public class HazelcastIntentBatchQueue |
82 | 82 | ||
83 | 83 | ||
84 | private HazelcastInstance theInstance; | 84 | private HazelcastInstance theInstance; |
85 | - private ControllerNode localControllerNode; | 85 | + private NodeId localControllerNodeId; |
86 | protected StoreSerializer serializer; | 86 | protected StoreSerializer serializer; |
87 | private IntentBatchDelegate delegate; | 87 | private IntentBatchDelegate delegate; |
88 | private InternalLeaderListener leaderListener = new InternalLeaderListener(); | 88 | private InternalLeaderListener leaderListener = new InternalLeaderListener(); |
... | @@ -98,7 +98,7 @@ public class HazelcastIntentBatchQueue | ... | @@ -98,7 +98,7 @@ public class HazelcastIntentBatchQueue |
98 | @Activate | 98 | @Activate |
99 | public void activate() { | 99 | public void activate() { |
100 | theInstance = storeService.getHazelcastInstance(); | 100 | theInstance = storeService.getHazelcastInstance(); |
101 | - localControllerNode = clusterService.getLocalNode(); | 101 | + localControllerNodeId = clusterService.getLocalNode().id(); |
102 | leadershipService.addListener(leaderListener); | 102 | leadershipService.addListener(leaderListener); |
103 | 103 | ||
104 | serializer = new KryoSerializer() { | 104 | serializer = new KryoSerializer() { |
... | @@ -254,7 +254,7 @@ public class HazelcastIntentBatchQueue | ... | @@ -254,7 +254,7 @@ public class HazelcastIntentBatchQueue |
254 | if (!topic.startsWith(TOPIC_BASE)) { | 254 | if (!topic.startsWith(TOPIC_BASE)) { |
255 | return; // Not our topic: ignore | 255 | return; // Not our topic: ignore |
256 | } | 256 | } |
257 | - if (!event.subject().leader().id().equals(localControllerNode.id())) { | 257 | + if (!event.subject().leader().equals(localControllerNodeId)) { |
258 | // run for leadership | 258 | // run for leadership |
259 | getQueue(getAppId(topic)); | 259 | getQueue(getAppId(topic)); |
260 | return; // The event is not about this instance: ignore | 260 | return; // The event is not about this instance: ignore | ... | ... |
... | @@ -10,12 +10,12 @@ import org.apache.felix.scr.annotations.Reference; | ... | @@ -10,12 +10,12 @@ import org.apache.felix.scr.annotations.Reference; |
10 | import org.apache.felix.scr.annotations.ReferenceCardinality; | 10 | import org.apache.felix.scr.annotations.ReferenceCardinality; |
11 | import org.apache.felix.scr.annotations.Service; | 11 | import org.apache.felix.scr.annotations.Service; |
12 | import org.onlab.onos.cluster.ClusterService; | 12 | import org.onlab.onos.cluster.ClusterService; |
13 | -import org.onlab.onos.cluster.ControllerNode; | ||
14 | import org.onlab.onos.cluster.Leadership; | 13 | import org.onlab.onos.cluster.Leadership; |
15 | import org.onlab.onos.cluster.LeadershipEvent; | 14 | import org.onlab.onos.cluster.LeadershipEvent; |
16 | import org.onlab.onos.cluster.LeadershipEvent.Type; | 15 | import org.onlab.onos.cluster.LeadershipEvent.Type; |
17 | import org.onlab.onos.cluster.LeadershipEventListener; | 16 | import org.onlab.onos.cluster.LeadershipEventListener; |
18 | import org.onlab.onos.cluster.LeadershipService; | 17 | import org.onlab.onos.cluster.LeadershipService; |
18 | +import org.onlab.onos.cluster.NodeId; | ||
19 | 19 | ||
20 | /** | 20 | /** |
21 | * A trivial implementation of the leadership service. | 21 | * A trivial implementation of the leadership service. |
... | @@ -35,8 +35,8 @@ public class SimpleLeadershipManager implements LeadershipService { | ... | @@ -35,8 +35,8 @@ public class SimpleLeadershipManager implements LeadershipService { |
35 | private Map<String, Boolean> elections = new ConcurrentHashMap<>(); | 35 | private Map<String, Boolean> elections = new ConcurrentHashMap<>(); |
36 | 36 | ||
37 | @Override | 37 | @Override |
38 | - public ControllerNode getLeader(String path) { | 38 | + public NodeId getLeader(String path) { |
39 | - return elections.get(path) ? clusterService.getLocalNode() : null; | 39 | + return elections.get(path) ? clusterService.getLocalNode().id() : null; |
40 | } | 40 | } |
41 | 41 | ||
42 | @Override | 42 | @Override |
... | @@ -44,7 +44,7 @@ public class SimpleLeadershipManager implements LeadershipService { | ... | @@ -44,7 +44,7 @@ public class SimpleLeadershipManager implements LeadershipService { |
44 | elections.put(path, true); | 44 | elections.put(path, true); |
45 | for (LeadershipEventListener listener : listeners) { | 45 | for (LeadershipEventListener listener : listeners) { |
46 | listener.event(new LeadershipEvent(Type.LEADER_ELECTED, | 46 | listener.event(new LeadershipEvent(Type.LEADER_ELECTED, |
47 | - new Leadership(path, clusterService.getLocalNode(), 0))); | 47 | + new Leadership(path, clusterService.getLocalNode().id(), 0))); |
48 | } | 48 | } |
49 | } | 49 | } |
50 | 50 | ||
... | @@ -53,7 +53,7 @@ public class SimpleLeadershipManager implements LeadershipService { | ... | @@ -53,7 +53,7 @@ public class SimpleLeadershipManager implements LeadershipService { |
53 | elections.remove(path); | 53 | elections.remove(path); |
54 | for (LeadershipEventListener listener : listeners) { | 54 | for (LeadershipEventListener listener : listeners) { |
55 | listener.event(new LeadershipEvent(Type.LEADER_BOOTED, | 55 | listener.event(new LeadershipEvent(Type.LEADER_BOOTED, |
56 | - new Leadership(path, clusterService.getLocalNode(), 0))); | 56 | + new Leadership(path, clusterService.getLocalNode().id(), 0))); |
57 | } | 57 | } |
58 | } | 58 | } |
59 | 59 | ... | ... |
-
Please register or login to post a comment