Committed by
Gerrit Code Review
Refactored IntentPartitionService as WorkPartitionService
Change-Id: Ic5cf1978b7fce55b34f84eae9b03c8f9ddcfb9c1
Showing
14 changed files
with
113 additions
and
121 deletions
... | @@ -51,7 +51,7 @@ import org.onosproject.net.intent.IntentEvent; | ... | @@ -51,7 +51,7 @@ import org.onosproject.net.intent.IntentEvent; |
51 | import org.onosproject.net.intent.IntentListener; | 51 | import org.onosproject.net.intent.IntentListener; |
52 | import org.onosproject.net.intent.IntentService; | 52 | import org.onosproject.net.intent.IntentService; |
53 | import org.onosproject.net.intent.Key; | 53 | import org.onosproject.net.intent.Key; |
54 | -import org.onosproject.net.intent.IntentPartitionService; | 54 | +import org.onosproject.net.intent.WorkPartitionService; |
55 | import org.onosproject.net.intent.PointToPointIntent; | 55 | import org.onosproject.net.intent.PointToPointIntent; |
56 | import org.onosproject.store.cluster.messaging.ClusterCommunicationService; | 56 | import org.onosproject.store.cluster.messaging.ClusterCommunicationService; |
57 | import org.onosproject.store.cluster.messaging.MessageSubject; | 57 | import org.onosproject.store.cluster.messaging.MessageSubject; |
... | @@ -139,7 +139,7 @@ public class IntentPerfInstaller { | ... | @@ -139,7 +139,7 @@ public class IntentPerfInstaller { |
139 | protected MastershipService mastershipService; | 139 | protected MastershipService mastershipService; |
140 | 140 | ||
141 | @Reference(cardinality = MANDATORY_UNARY) | 141 | @Reference(cardinality = MANDATORY_UNARY) |
142 | - protected IntentPartitionService partitionService; | 142 | + protected WorkPartitionService partitionService; |
143 | 143 | ||
144 | @Reference(cardinality = MANDATORY_UNARY) | 144 | @Reference(cardinality = MANDATORY_UNARY) |
145 | protected ComponentConfigService configService; | 145 | protected ComponentConfigService configService; |
... | @@ -371,7 +371,7 @@ public class IntentPerfInstaller { | ... | @@ -371,7 +371,7 @@ public class IntentPerfInstaller { |
371 | for (int count = 0, k = firstKey; count < numberOfKeys; k++) { | 371 | for (int count = 0, k = firstKey; count < numberOfKeys; k++) { |
372 | Key key = Key.of(keyPrefix + k, appId); | 372 | Key key = Key.of(keyPrefix + k, appId); |
373 | 373 | ||
374 | - NodeId leader = partitionService.getLeader(key); | 374 | + NodeId leader = partitionService.getLeader(key, Key::hash); |
375 | if (!neighbors.contains(leader) || intents.get(leader).size() >= maxKeysPerNode) { | 375 | if (!neighbors.contains(leader) || intents.get(leader).size() >= maxKeysPerNode) { |
376 | // Bail if we are not sending to this node or we have enough for this node | 376 | // Bail if we are not sending to this node or we have enough for this node |
377 | continue; | 377 | continue; | ... | ... |
... | @@ -23,13 +23,13 @@ import org.onosproject.event.AbstractEvent; | ... | @@ -23,13 +23,13 @@ import org.onosproject.event.AbstractEvent; |
23 | */ | 23 | */ |
24 | //TODO change String into a proper object type | 24 | //TODO change String into a proper object type |
25 | @Beta | 25 | @Beta |
26 | -public class IntentPartitionEvent extends AbstractEvent<IntentPartitionEvent.Type, String> { | 26 | +public class WorkPartitionEvent extends AbstractEvent<WorkPartitionEvent.Type, String> { |
27 | 27 | ||
28 | public enum Type { | 28 | public enum Type { |
29 | LEADER_CHANGED | 29 | LEADER_CHANGED |
30 | } | 30 | } |
31 | 31 | ||
32 | - public IntentPartitionEvent(Type type, String partition) { | 32 | + public WorkPartitionEvent(Type type, String partition) { |
33 | super(type, partition); | 33 | super(type, partition); |
34 | } | 34 | } |
35 | } | 35 | } | ... | ... |
... | @@ -22,5 +22,5 @@ import org.onosproject.event.EventListener; | ... | @@ -22,5 +22,5 @@ import org.onosproject.event.EventListener; |
22 | * Entity capable of receiving device partition-related events. | 22 | * Entity capable of receiving device partition-related events. |
23 | */ | 23 | */ |
24 | @Beta | 24 | @Beta |
25 | -public interface IntentPartitionEventListener extends EventListener<IntentPartitionEvent> { | 25 | +public interface WorkPartitionEventListener extends EventListener<WorkPartitionEvent> { |
26 | } | 26 | } | ... | ... |
... | @@ -15,34 +15,36 @@ | ... | @@ -15,34 +15,36 @@ |
15 | */ | 15 | */ |
16 | package org.onosproject.net.intent; | 16 | package org.onosproject.net.intent; |
17 | 17 | ||
18 | -import com.google.common.annotations.Beta; | 18 | +import java.util.function.Function; |
19 | + | ||
19 | import org.onosproject.cluster.NodeId; | 20 | import org.onosproject.cluster.NodeId; |
20 | import org.onosproject.event.ListenerService; | 21 | import org.onosproject.event.ListenerService; |
21 | 22 | ||
23 | +import com.google.common.annotations.Beta; | ||
24 | + | ||
22 | /** | 25 | /** |
23 | - * Service for interacting with the intent partition-to-instance assignments. | 26 | + * Service for partitioning work, represented via a unique identifier, onto cluster nodes. |
24 | */ | 27 | */ |
25 | @Beta | 28 | @Beta |
26 | -public interface IntentPartitionService | 29 | +public interface WorkPartitionService |
27 | - extends ListenerService<IntentPartitionEvent, IntentPartitionEventListener> { | 30 | + extends ListenerService<WorkPartitionEvent, WorkPartitionEventListener> { |
28 | 31 | ||
29 | /** | 32 | /** |
30 | - * Returns whether the given intent key is in a partition owned by this | 33 | + * Returns whether a given id maps to a partition owned by this |
31 | - * instance or not. | 34 | + * instance. |
32 | * | 35 | * |
33 | - * @param intentKey intent key to query | 36 | + * @param id id |
34 | - * @return true if the key is owned by this instance, otherwise false | 37 | + * @param hasher function that maps id to a long value |
38 | + * @return {@code true} if the id maps to a partition owned by this instance, otherwise {@code false} | ||
35 | */ | 39 | */ |
36 | - boolean isMine(Key intentKey); | 40 | + <K> boolean isMine(K id, Function<K, Long> hasher); |
37 | 41 | ||
38 | /** | 42 | /** |
39 | - * Returns the leader for a particular key. | 43 | + * Returns the owner for a given id. |
40 | * | 44 | * |
41 | - * @param intentKey intent key to query | 45 | + * @param id id to query |
42 | - * @return the leader node | 46 | + * @param hasher function that maps id to a long value |
47 | + * @return the leader node identifier | ||
43 | */ | 48 | */ |
44 | - NodeId getLeader(Key intentKey); | 49 | + <K> NodeId getLeader(K id, Function<K, Long> hasher); |
45 | - | ||
46 | - // TODO add API for rebalancing partitions | ||
47 | - | ||
48 | } | 50 | } | ... | ... |
... | @@ -15,29 +15,31 @@ | ... | @@ -15,29 +15,31 @@ |
15 | */ | 15 | */ |
16 | package org.onosproject.net.intent; | 16 | package org.onosproject.net.intent; |
17 | 17 | ||
18 | +import java.util.function.Function; | ||
19 | + | ||
18 | import org.onosproject.cluster.NodeId; | 20 | import org.onosproject.cluster.NodeId; |
19 | 21 | ||
20 | /** | 22 | /** |
21 | - * Testing adapter for the IntentPartitionService. | 23 | + * Testing adapter for the WorkPartitionService. |
22 | */ | 24 | */ |
23 | -public class IntentPartitionServiceAdapter implements IntentPartitionService { | 25 | +public class WorkPartitionServiceAdapter implements WorkPartitionService { |
24 | @Override | 26 | @Override |
25 | - public boolean isMine(Key intentKey) { | 27 | + public <K> boolean isMine(K id, Function<K, Long> hasher) { |
26 | return true; | 28 | return true; |
27 | } | 29 | } |
28 | 30 | ||
29 | @Override | 31 | @Override |
30 | - public NodeId getLeader(Key intentKey) { | 32 | + public <K> NodeId getLeader(K id, Function<K, Long> hasher) { |
31 | return null; | 33 | return null; |
32 | } | 34 | } |
33 | 35 | ||
34 | @Override | 36 | @Override |
35 | - public void addListener(IntentPartitionEventListener listener) { | 37 | + public void addListener(WorkPartitionEventListener listener) { |
36 | 38 | ||
37 | } | 39 | } |
38 | 40 | ||
39 | @Override | 41 | @Override |
40 | - public void removeListener(IntentPartitionEventListener listener) { | 42 | + public void removeListener(WorkPartitionEventListener listener) { |
41 | 43 | ||
42 | } | 44 | } |
43 | } | 45 | } | ... | ... |
... | @@ -16,6 +16,7 @@ | ... | @@ -16,6 +16,7 @@ |
16 | package org.onosproject.store.trivial; | 16 | package org.onosproject.store.trivial; |
17 | 17 | ||
18 | import com.google.common.collect.ImmutableSet; | 18 | import com.google.common.collect.ImmutableSet; |
19 | + | ||
19 | import org.apache.felix.scr.annotations.Activate; | 20 | import org.apache.felix.scr.annotations.Activate; |
20 | import org.apache.felix.scr.annotations.Component; | 21 | import org.apache.felix.scr.annotations.Component; |
21 | import org.apache.felix.scr.annotations.Deactivate; | 22 | import org.apache.felix.scr.annotations.Deactivate; |
... | @@ -32,14 +33,14 @@ import org.onosproject.cluster.DefaultControllerNode; | ... | @@ -32,14 +33,14 @@ import org.onosproject.cluster.DefaultControllerNode; |
32 | import org.onosproject.cluster.NodeId; | 33 | import org.onosproject.cluster.NodeId; |
33 | import org.onosproject.event.EventDeliveryService; | 34 | import org.onosproject.event.EventDeliveryService; |
34 | import org.onosproject.event.ListenerRegistry; | 35 | import org.onosproject.event.ListenerRegistry; |
35 | -import org.onosproject.net.intent.Key; | 36 | +import org.onosproject.net.intent.WorkPartitionEvent; |
36 | -import org.onosproject.net.intent.IntentPartitionEvent; | 37 | +import org.onosproject.net.intent.WorkPartitionEventListener; |
37 | -import org.onosproject.net.intent.IntentPartitionEventListener; | 38 | +import org.onosproject.net.intent.WorkPartitionService; |
38 | -import org.onosproject.net.intent.IntentPartitionService; | ||
39 | import org.onosproject.store.AbstractStore; | 39 | import org.onosproject.store.AbstractStore; |
40 | import org.slf4j.Logger; | 40 | import org.slf4j.Logger; |
41 | 41 | ||
42 | import java.util.Set; | 42 | import java.util.Set; |
43 | +import java.util.function.Function; | ||
43 | 44 | ||
44 | import static org.onosproject.security.AppGuard.checkPermission; | 45 | import static org.onosproject.security.AppGuard.checkPermission; |
45 | import static org.onosproject.security.AppPermission.Type.*; | 46 | import static org.onosproject.security.AppPermission.Type.*; |
... | @@ -53,7 +54,7 @@ import static org.slf4j.LoggerFactory.getLogger; | ... | @@ -53,7 +54,7 @@ import static org.slf4j.LoggerFactory.getLogger; |
53 | @Service | 54 | @Service |
54 | public class SimpleClusterStore | 55 | public class SimpleClusterStore |
55 | extends AbstractStore<ClusterEvent, ClusterStoreDelegate> | 56 | extends AbstractStore<ClusterEvent, ClusterStoreDelegate> |
56 | - implements ClusterStore, IntentPartitionService { | 57 | + implements ClusterStore, WorkPartitionService { |
57 | 58 | ||
58 | public static final IpAddress LOCALHOST = IpAddress.valueOf("127.0.0.1"); | 59 | public static final IpAddress LOCALHOST = IpAddress.valueOf("127.0.0.1"); |
59 | 60 | ||
... | @@ -66,7 +67,7 @@ public class SimpleClusterStore | ... | @@ -66,7 +67,7 @@ public class SimpleClusterStore |
66 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) | 67 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
67 | protected EventDeliveryService eventDispatcher; | 68 | protected EventDeliveryService eventDispatcher; |
68 | 69 | ||
69 | - private ListenerRegistry<IntentPartitionEvent, IntentPartitionEventListener> listenerRegistry; | 70 | + private ListenerRegistry<WorkPartitionEvent, WorkPartitionEventListener> listenerRegistry; |
70 | private boolean started = false; | 71 | private boolean started = false; |
71 | 72 | ||
72 | @Activate | 73 | @Activate |
... | @@ -74,14 +75,14 @@ public class SimpleClusterStore | ... | @@ -74,14 +75,14 @@ public class SimpleClusterStore |
74 | instance = new DefaultControllerNode(new NodeId("local"), LOCALHOST); | 75 | instance = new DefaultControllerNode(new NodeId("local"), LOCALHOST); |
75 | 76 | ||
76 | listenerRegistry = new ListenerRegistry<>(); | 77 | listenerRegistry = new ListenerRegistry<>(); |
77 | - eventDispatcher.addSink(IntentPartitionEvent.class, listenerRegistry); | 78 | + eventDispatcher.addSink(WorkPartitionEvent.class, listenerRegistry); |
78 | 79 | ||
79 | log.info("Started"); | 80 | log.info("Started"); |
80 | } | 81 | } |
81 | 82 | ||
82 | @Deactivate | 83 | @Deactivate |
83 | public void deactivate() { | 84 | public void deactivate() { |
84 | - eventDispatcher.removeSink(IntentPartitionEvent.class); | 85 | + eventDispatcher.removeSink(WorkPartitionEvent.class); |
85 | log.info("Stopped"); | 86 | log.info("Stopped"); |
86 | } | 87 | } |
87 | 88 | ||
... | @@ -126,25 +127,25 @@ public class SimpleClusterStore | ... | @@ -126,25 +127,25 @@ public class SimpleClusterStore |
126 | } | 127 | } |
127 | 128 | ||
128 | @Override | 129 | @Override |
129 | - public boolean isMine(Key intentKey) { | 130 | + public <K> boolean isMine(K key, Function<K, Long> hasher) { |
130 | checkPermission(INTENT_READ); | 131 | checkPermission(INTENT_READ); |
131 | return true; | 132 | return true; |
132 | } | 133 | } |
133 | 134 | ||
134 | @Override | 135 | @Override |
135 | - public NodeId getLeader(Key intentKey) { | 136 | + public <K> NodeId getLeader(K key, Function<K, Long> hasher) { |
136 | checkPermission(INTENT_READ); | 137 | checkPermission(INTENT_READ); |
137 | return instance.id(); | 138 | return instance.id(); |
138 | } | 139 | } |
139 | 140 | ||
140 | @Override | 141 | @Override |
141 | - public void addListener(IntentPartitionEventListener listener) { | 142 | + public void addListener(WorkPartitionEventListener listener) { |
142 | checkPermission(INTENT_EVENT); | 143 | checkPermission(INTENT_EVENT); |
143 | listenerRegistry.addListener(listener); | 144 | listenerRegistry.addListener(listener); |
144 | } | 145 | } |
145 | 146 | ||
146 | @Override | 147 | @Override |
147 | - public void removeListener(IntentPartitionEventListener listener) { | 148 | + public void removeListener(WorkPartitionEventListener listener) { |
148 | checkPermission(INTENT_EVENT); | 149 | checkPermission(INTENT_EVENT); |
149 | listenerRegistry.removeListener(listener); | 150 | listenerRegistry.removeListener(listener); |
150 | } | 151 | } | ... | ... |
... | @@ -43,9 +43,9 @@ import org.onosproject.net.intent.Intent; | ... | @@ -43,9 +43,9 @@ import org.onosproject.net.intent.Intent; |
43 | import org.onosproject.net.intent.IntentData; | 43 | import org.onosproject.net.intent.IntentData; |
44 | import org.onosproject.net.intent.IntentService; | 44 | import org.onosproject.net.intent.IntentService; |
45 | import org.onosproject.net.intent.Key; | 45 | import org.onosproject.net.intent.Key; |
46 | -import org.onosproject.net.intent.IntentPartitionEvent; | 46 | +import org.onosproject.net.intent.WorkPartitionEvent; |
47 | -import org.onosproject.net.intent.IntentPartitionEventListener; | 47 | +import org.onosproject.net.intent.WorkPartitionEventListener; |
48 | -import org.onosproject.net.intent.IntentPartitionService; | 48 | +import org.onosproject.net.intent.WorkPartitionService; |
49 | import org.onosproject.net.link.LinkEvent; | 49 | import org.onosproject.net.link.LinkEvent; |
50 | import org.onosproject.net.resource.ResourceEvent; | 50 | import org.onosproject.net.resource.ResourceEvent; |
51 | import org.onosproject.net.resource.ResourceListener; | 51 | import org.onosproject.net.resource.ResourceListener; |
... | @@ -113,7 +113,7 @@ public class ObjectiveTracker implements ObjectiveTrackerService { | ... | @@ -113,7 +113,7 @@ public class ObjectiveTracker implements ObjectiveTrackerService { |
113 | protected IntentService intentService; | 113 | protected IntentService intentService; |
114 | 114 | ||
115 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) | 115 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
116 | - protected IntentPartitionService partitionService; | 116 | + protected WorkPartitionService partitionService; |
117 | 117 | ||
118 | private ExecutorService executorService = | 118 | private ExecutorService executorService = |
119 | newSingleThreadExecutor(groupedThreads("onos/intent", "objectivetracker", log)); | 119 | newSingleThreadExecutor(groupedThreads("onos/intent", "objectivetracker", log)); |
... | @@ -124,7 +124,7 @@ public class ObjectiveTracker implements ObjectiveTrackerService { | ... | @@ -124,7 +124,7 @@ public class ObjectiveTracker implements ObjectiveTrackerService { |
124 | private ResourceListener resourceListener = new InternalResourceListener(); | 124 | private ResourceListener resourceListener = new InternalResourceListener(); |
125 | private DeviceListener deviceListener = new InternalDeviceListener(); | 125 | private DeviceListener deviceListener = new InternalDeviceListener(); |
126 | private HostListener hostListener = new InternalHostListener(); | 126 | private HostListener hostListener = new InternalHostListener(); |
127 | - private IntentPartitionEventListener partitionListener = new InternalPartitionListener(); | 127 | + private WorkPartitionEventListener partitionListener = new InternalPartitionListener(); |
128 | private TopologyChangeDelegate delegate; | 128 | private TopologyChangeDelegate delegate; |
129 | 129 | ||
130 | protected final AtomicBoolean updateScheduled = new AtomicBoolean(false); | 130 | protected final AtomicBoolean updateScheduled = new AtomicBoolean(false); |
... | @@ -417,9 +417,9 @@ public class ObjectiveTracker implements ObjectiveTrackerService { | ... | @@ -417,9 +417,9 @@ public class ObjectiveTracker implements ObjectiveTrackerService { |
417 | } | 417 | } |
418 | } | 418 | } |
419 | 419 | ||
420 | - private final class InternalPartitionListener implements IntentPartitionEventListener { | 420 | + private final class InternalPartitionListener implements WorkPartitionEventListener { |
421 | @Override | 421 | @Override |
422 | - public void event(IntentPartitionEvent event) { | 422 | + public void event(WorkPartitionEvent event) { |
423 | log.debug("got message {}", event.subject()); | 423 | log.debug("got message {}", event.subject()); |
424 | scheduleIntentUpdate(1); | 424 | scheduleIntentUpdate(1); |
425 | } | 425 | } | ... | ... |
... | @@ -59,7 +59,7 @@ import org.onosproject.net.host.HostService; | ... | @@ -59,7 +59,7 @@ import org.onosproject.net.host.HostService; |
59 | import org.onosproject.net.intent.IntentService; | 59 | import org.onosproject.net.intent.IntentService; |
60 | import org.onosproject.net.intent.IntentExtensionService; | 60 | import org.onosproject.net.intent.IntentExtensionService; |
61 | import org.onosproject.net.intent.IntentClockService; | 61 | import org.onosproject.net.intent.IntentClockService; |
62 | -import org.onosproject.net.intent.IntentPartitionService; | 62 | +import org.onosproject.net.intent.WorkPartitionService; |
63 | import org.onosproject.net.link.LinkAdminService; | 63 | import org.onosproject.net.link.LinkAdminService; |
64 | import org.onosproject.net.link.LinkService; | 64 | import org.onosproject.net.link.LinkService; |
65 | import org.onosproject.net.packet.PacketService; | 65 | import org.onosproject.net.packet.PacketService; |
... | @@ -227,7 +227,7 @@ public final class DefaultPolicyBuilder { | ... | @@ -227,7 +227,7 @@ public final class DefaultPolicyBuilder { |
227 | permSet.add(new ServicePermission(IntentService.class.getName(), ServicePermission.GET)); | 227 | permSet.add(new ServicePermission(IntentService.class.getName(), ServicePermission.GET)); |
228 | permSet.add(new ServicePermission(IntentClockService.class.getName(), ServicePermission.GET)); | 228 | permSet.add(new ServicePermission(IntentClockService.class.getName(), ServicePermission.GET)); |
229 | permSet.add(new ServicePermission(IntentExtensionService.class.getName(), ServicePermission.GET)); | 229 | permSet.add(new ServicePermission(IntentExtensionService.class.getName(), ServicePermission.GET)); |
230 | - permSet.add(new ServicePermission(IntentPartitionService.class.getName(), ServicePermission.GET)); | 230 | + permSet.add(new ServicePermission(WorkPartitionService.class.getName(), ServicePermission.GET)); |
231 | permSet.add(new ServicePermission(DeviceKeyService.class.getName(), ServicePermission.GET)); | 231 | permSet.add(new ServicePermission(DeviceKeyService.class.getName(), ServicePermission.GET)); |
232 | permSet.add(new ServicePermission(LinkService.class.getName(), ServicePermission.GET)); | 232 | permSet.add(new ServicePermission(LinkService.class.getName(), ServicePermission.GET)); |
233 | // permSet.add(new ServicePermission(MulticastRouteService.class.getName(), ServicePermission.GET)); | 233 | // permSet.add(new ServicePermission(MulticastRouteService.class.getName(), ServicePermission.GET)); |
... | @@ -314,12 +314,12 @@ public final class DefaultPolicyBuilder { | ... | @@ -314,12 +314,12 @@ public final class DefaultPolicyBuilder { |
314 | serviceDirectory.put(HOST_EVENT, ImmutableSet.of( | 314 | serviceDirectory.put(HOST_EVENT, ImmutableSet.of( |
315 | HostService.class.getName())); | 315 | HostService.class.getName())); |
316 | serviceDirectory.put(INTENT_READ, ImmutableSet.of( | 316 | serviceDirectory.put(INTENT_READ, ImmutableSet.of( |
317 | - IntentService.class.getName(), IntentPartitionService.class.getName(), | 317 | + IntentService.class.getName(), WorkPartitionService.class.getName(), |
318 | IntentClockService.class.getName(), IntentExtensionService.class.getName())); | 318 | IntentClockService.class.getName(), IntentExtensionService.class.getName())); |
319 | serviceDirectory.put(INTENT_WRITE, ImmutableSet.of( | 319 | serviceDirectory.put(INTENT_WRITE, ImmutableSet.of( |
320 | IntentService.class.getName(), IntentExtensionService.class.getName())); | 320 | IntentService.class.getName(), IntentExtensionService.class.getName())); |
321 | serviceDirectory.put(INTENT_EVENT, ImmutableSet.of( | 321 | serviceDirectory.put(INTENT_EVENT, ImmutableSet.of( |
322 | - IntentService.class.getName(), IntentPartitionService.class.getName())); | 322 | + IntentService.class.getName(), WorkPartitionService.class.getName())); |
323 | // serviceDirectory.put(LINK_READ, ImmutableSet.of( | 323 | // serviceDirectory.put(LINK_READ, ImmutableSet.of( |
324 | // LinkService.class.getName(), LinkResourceService.class.getName(), | 324 | // LinkService.class.getName(), LinkResourceService.class.getName(), |
325 | // LabelResourceService.class.getName())); | 325 | // LabelResourceService.class.getName())); | ... | ... |
... | @@ -32,7 +32,7 @@ import org.onosproject.incubator.net.virtual.VirtualNetworkIntent; | ... | @@ -32,7 +32,7 @@ import org.onosproject.incubator.net.virtual.VirtualNetworkIntent; |
32 | import org.onosproject.net.intent.Intent; | 32 | import org.onosproject.net.intent.Intent; |
33 | import org.onosproject.net.intent.IntentData; | 33 | import org.onosproject.net.intent.IntentData; |
34 | import org.onosproject.net.intent.IntentEvent; | 34 | import org.onosproject.net.intent.IntentEvent; |
35 | -import org.onosproject.net.intent.IntentPartitionService; | 35 | +import org.onosproject.net.intent.WorkPartitionService; |
36 | import org.onosproject.net.intent.IntentState; | 36 | import org.onosproject.net.intent.IntentState; |
37 | import org.onosproject.net.intent.IntentStore; | 37 | import org.onosproject.net.intent.IntentStore; |
38 | import org.onosproject.net.intent.IntentStoreDelegate; | 38 | import org.onosproject.net.intent.IntentStoreDelegate; |
... | @@ -84,7 +84,7 @@ public class GossipIntentStore | ... | @@ -84,7 +84,7 @@ public class GossipIntentStore |
84 | protected StorageService storageService; | 84 | protected StorageService storageService; |
85 | 85 | ||
86 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) | 86 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
87 | - protected IntentPartitionService partitionService; | 87 | + protected WorkPartitionService partitionService; |
88 | 88 | ||
89 | private final AtomicLong sequenceNumber = new AtomicLong(0); | 89 | private final AtomicLong sequenceNumber = new AtomicLong(0); |
90 | 90 | ||
... | @@ -211,7 +211,7 @@ public class GossipIntentStore | ... | @@ -211,7 +211,7 @@ public class GossipIntentStore |
211 | } | 211 | } |
212 | 212 | ||
213 | private Collection<NodeId> getPeerNodes(Key key, IntentData data) { | 213 | private Collection<NodeId> getPeerNodes(Key key, IntentData data) { |
214 | - NodeId master = partitionService.getLeader(key); | 214 | + NodeId master = partitionService.getLeader(key, Key::hash); |
215 | NodeId origin = (data != null) ? data.origin() : null; | 215 | NodeId origin = (data != null) ? data.origin() : null; |
216 | if (data != null && (master == null || origin == null)) { | 216 | if (data != null && (master == null || origin == null)) { |
217 | log.debug("Intent {} missing master and/or origin; master = {}, origin = {}", | 217 | log.debug("Intent {} missing master and/or origin; master = {}, origin = {}", |
... | @@ -283,7 +283,7 @@ public class GossipIntentStore | ... | @@ -283,7 +283,7 @@ public class GossipIntentStore |
283 | 283 | ||
284 | @Override | 284 | @Override |
285 | public boolean isMaster(Key intentKey) { | 285 | public boolean isMaster(Key intentKey) { |
286 | - return partitionService.isMine(intentKey); | 286 | + return partitionService.isMine(intentKey, Key::hash); |
287 | } | 287 | } |
288 | 288 | ||
289 | @Override | 289 | @Override | ... | ... |
... | @@ -29,10 +29,9 @@ import org.onosproject.cluster.LeadershipService; | ... | @@ -29,10 +29,9 @@ import org.onosproject.cluster.LeadershipService; |
29 | import org.onosproject.cluster.NodeId; | 29 | import org.onosproject.cluster.NodeId; |
30 | import org.onosproject.event.EventDeliveryService; | 30 | import org.onosproject.event.EventDeliveryService; |
31 | import org.onosproject.event.ListenerRegistry; | 31 | import org.onosproject.event.ListenerRegistry; |
32 | -import org.onosproject.net.intent.IntentPartitionEvent; | 32 | +import org.onosproject.net.intent.WorkPartitionEvent; |
33 | -import org.onosproject.net.intent.IntentPartitionEventListener; | 33 | +import org.onosproject.net.intent.WorkPartitionEventListener; |
34 | -import org.onosproject.net.intent.IntentPartitionService; | 34 | +import org.onosproject.net.intent.WorkPartitionService; |
35 | -import org.onosproject.net.intent.Key; | ||
36 | import org.slf4j.Logger; | 35 | import org.slf4j.Logger; |
37 | import org.slf4j.LoggerFactory; | 36 | import org.slf4j.LoggerFactory; |
38 | 37 | ||
... | @@ -44,17 +43,18 @@ import java.util.concurrent.Executors; | ... | @@ -44,17 +43,18 @@ import java.util.concurrent.Executors; |
44 | import java.util.concurrent.ScheduledExecutorService; | 43 | import java.util.concurrent.ScheduledExecutorService; |
45 | import java.util.concurrent.TimeUnit; | 44 | import java.util.concurrent.TimeUnit; |
46 | import java.util.concurrent.atomic.AtomicBoolean; | 45 | import java.util.concurrent.atomic.AtomicBoolean; |
46 | +import java.util.function.Function; | ||
47 | import java.util.stream.Collectors; | 47 | import java.util.stream.Collectors; |
48 | import java.util.stream.IntStream; | 48 | import java.util.stream.IntStream; |
49 | 49 | ||
50 | /** | 50 | /** |
51 | - * Manages the assignment of intent keyspace partitions to instances. | 51 | + * Manages the assignment of work partitions to instances. |
52 | */ | 52 | */ |
53 | @Component(immediate = true) | 53 | @Component(immediate = true) |
54 | @Service | 54 | @Service |
55 | -public class IntentPartitionManager implements IntentPartitionService { | 55 | +public class WorkPartitionManager implements WorkPartitionService { |
56 | 56 | ||
57 | - private static final Logger log = LoggerFactory.getLogger(IntentPartitionManager.class); | 57 | + private static final Logger log = LoggerFactory.getLogger(WorkPartitionManager.class); |
58 | 58 | ||
59 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) | 59 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
60 | protected LeadershipService leadershipService; | 60 | protected LeadershipService leadershipService; |
... | @@ -72,14 +72,14 @@ public class IntentPartitionManager implements IntentPartitionService { | ... | @@ -72,14 +72,14 @@ public class IntentPartitionManager implements IntentPartitionService { |
72 | private static final int CHECK_PARTITION_BALANCE_PERIOD_SEC = 10; | 72 | private static final int CHECK_PARTITION_BALANCE_PERIOD_SEC = 10; |
73 | private static final int RETRY_AFTER_DELAY_SEC = 5; | 73 | private static final int RETRY_AFTER_DELAY_SEC = 5; |
74 | 74 | ||
75 | - private static final String ELECTION_PREFIX = "intent-partition-"; | 75 | + private static final String ELECTION_PREFIX = "work-partition-"; |
76 | 76 | ||
77 | protected NodeId localNodeId; | 77 | protected NodeId localNodeId; |
78 | - private ListenerRegistry<IntentPartitionEvent, IntentPartitionEventListener> listenerRegistry; | 78 | + private ListenerRegistry<WorkPartitionEvent, WorkPartitionEventListener> listenerRegistry; |
79 | private LeadershipEventListener leaderListener = new InternalLeadershipListener(); | 79 | private LeadershipEventListener leaderListener = new InternalLeadershipListener(); |
80 | 80 | ||
81 | private ScheduledExecutorService executor = Executors | 81 | private ScheduledExecutorService executor = Executors |
82 | - .newScheduledThreadPool(1, groupedThreads("IntentPartition", "balancer-%d", log)); | 82 | + .newScheduledThreadPool(1, groupedThreads("work-parition", "balancer-%d", log)); |
83 | 83 | ||
84 | @Activate | 84 | @Activate |
85 | public void activate() { | 85 | public void activate() { |
... | @@ -87,7 +87,7 @@ public class IntentPartitionManager implements IntentPartitionService { | ... | @@ -87,7 +87,7 @@ public class IntentPartitionManager implements IntentPartitionService { |
87 | leadershipService.addListener(leaderListener); | 87 | leadershipService.addListener(leaderListener); |
88 | 88 | ||
89 | listenerRegistry = new ListenerRegistry<>(); | 89 | listenerRegistry = new ListenerRegistry<>(); |
90 | - eventDispatcher.addSink(IntentPartitionEvent.class, listenerRegistry); | 90 | + eventDispatcher.addSink(WorkPartitionEvent.class, listenerRegistry); |
91 | 91 | ||
92 | for (int i = 0; i < NUM_PARTITIONS; i++) { | 92 | for (int i = 0; i < NUM_PARTITIONS; i++) { |
93 | leadershipService.runForLeadership(getPartitionPath(i)); | 93 | leadershipService.runForLeadership(getPartitionPath(i)); |
... | @@ -103,7 +103,7 @@ public class IntentPartitionManager implements IntentPartitionService { | ... | @@ -103,7 +103,7 @@ public class IntentPartitionManager implements IntentPartitionService { |
103 | public void deactivate() { | 103 | public void deactivate() { |
104 | executor.shutdownNow(); | 104 | executor.shutdownNow(); |
105 | 105 | ||
106 | - eventDispatcher.removeSink(IntentPartitionEvent.class); | 106 | + eventDispatcher.removeSink(WorkPartitionEvent.class); |
107 | leadershipService.removeListener(leaderListener); | 107 | leadershipService.removeListener(leaderListener); |
108 | log.info("Stopped"); | 108 | log.info("Stopped"); |
109 | } | 109 | } |
... | @@ -112,9 +112,9 @@ public class IntentPartitionManager implements IntentPartitionService { | ... | @@ -112,9 +112,9 @@ public class IntentPartitionManager implements IntentPartitionService { |
112 | * Sets the specified executor to be used for scheduling background tasks. | 112 | * Sets the specified executor to be used for scheduling background tasks. |
113 | * | 113 | * |
114 | * @param executor scheduled executor service for background tasks | 114 | * @param executor scheduled executor service for background tasks |
115 | - * @return this PartitionManager | 115 | + * @return this WorkPartitionManager |
116 | */ | 116 | */ |
117 | - IntentPartitionManager withScheduledExecutor(ScheduledExecutorService executor) { | 117 | + WorkPartitionManager withScheduledExecutor(ScheduledExecutorService executor) { |
118 | this.executor = executor; | 118 | this.executor = executor; |
119 | return this; | 119 | return this; |
120 | } | 120 | } |
... | @@ -123,38 +123,25 @@ public class IntentPartitionManager implements IntentPartitionService { | ... | @@ -123,38 +123,25 @@ public class IntentPartitionManager implements IntentPartitionService { |
123 | return ELECTION_PREFIX + i; | 123 | return ELECTION_PREFIX + i; |
124 | } | 124 | } |
125 | 125 | ||
126 | - private String getPartitionPath(PartitionId id) { | ||
127 | - return getPartitionPath(id.value()); | ||
128 | - } | ||
129 | - | ||
130 | - private PartitionId getPartitionForKey(Key intentKey) { | ||
131 | - int partition = Math.abs((int) intentKey.hash()) % NUM_PARTITIONS; | ||
132 | - //TODO investigate Guava consistent hash method | ||
133 | - // ... does it add significant computational complexity? is it worth it? | ||
134 | - //int partition = consistentHash(intentKey.hash(), NUM_PARTITIONS); | ||
135 | - PartitionId id = new PartitionId(partition); | ||
136 | - return id; | ||
137 | - } | ||
138 | - | ||
139 | @Override | 126 | @Override |
140 | - public boolean isMine(Key intentKey) { | 127 | + public <K> boolean isMine(K id, Function<K, Long> hasher) { |
141 | - return Objects.equals(leadershipService.getLeadership(getPartitionPath(getPartitionForKey(intentKey))) | 128 | + return Objects.equals(localNodeId, getLeader(id, hasher)); |
142 | - .leaderNodeId(), | ||
143 | - localNodeId); | ||
144 | } | 129 | } |
145 | 130 | ||
146 | @Override | 131 | @Override |
147 | - public NodeId getLeader(Key intentKey) { | 132 | + public <K> NodeId getLeader(K id, Function<K, Long> hasher) { |
148 | - return leadershipService.getLeader(getPartitionPath(getPartitionForKey(intentKey))); | 133 | + int partition = Math.abs(hasher.apply(id).intValue()) % NUM_PARTITIONS; |
134 | + PartitionId partitionId = new PartitionId(partition); | ||
135 | + return leadershipService.getLeadership(getPartitionPath(partitionId.value())).leaderNodeId(); | ||
149 | } | 136 | } |
150 | 137 | ||
151 | @Override | 138 | @Override |
152 | - public void addListener(IntentPartitionEventListener listener) { | 139 | + public void addListener(WorkPartitionEventListener listener) { |
153 | listenerRegistry.addListener(listener); | 140 | listenerRegistry.addListener(listener); |
154 | } | 141 | } |
155 | 142 | ||
156 | @Override | 143 | @Override |
157 | - public void removeListener(IntentPartitionEventListener listener) { | 144 | + public void removeListener(WorkPartitionEventListener listener) { |
158 | listenerRegistry.removeListener(listener); | 145 | listenerRegistry.removeListener(listener); |
159 | } | 146 | } |
160 | 147 | ||
... | @@ -235,7 +222,7 @@ public class IntentPartitionManager implements IntentPartitionService { | ... | @@ -235,7 +222,7 @@ public class IntentPartitionManager implements IntentPartitionService { |
235 | if (Objects.equals(leadership.leaderNodeId(), localNodeId) && | 222 | if (Objects.equals(leadership.leaderNodeId(), localNodeId) && |
236 | leadership.topic().startsWith(ELECTION_PREFIX)) { | 223 | leadership.topic().startsWith(ELECTION_PREFIX)) { |
237 | 224 | ||
238 | - eventDispatcher.post(new IntentPartitionEvent(IntentPartitionEvent.Type.LEADER_CHANGED, | 225 | + eventDispatcher.post(new WorkPartitionEvent(WorkPartitionEvent.Type.LEADER_CHANGED, |
239 | leadership.topic())); | 226 | leadership.topic())); |
240 | } | 227 | } |
241 | 228 | ... | ... |
... | @@ -30,7 +30,7 @@ import org.onosproject.net.intent.IntentData; | ... | @@ -30,7 +30,7 @@ import org.onosproject.net.intent.IntentData; |
30 | import org.onosproject.net.intent.IntentState; | 30 | import org.onosproject.net.intent.IntentState; |
31 | import org.onosproject.net.intent.IntentTestsMocks; | 31 | import org.onosproject.net.intent.IntentTestsMocks; |
32 | import org.onosproject.net.intent.MockIdGenerator; | 32 | import org.onosproject.net.intent.MockIdGenerator; |
33 | -import org.onosproject.net.intent.IntentPartitionServiceAdapter; | 33 | +import org.onosproject.net.intent.WorkPartitionServiceAdapter; |
34 | import org.onosproject.store.service.TestStorageService; | 34 | import org.onosproject.store.service.TestStorageService; |
35 | 35 | ||
36 | import static org.hamcrest.Matchers.is; | 36 | import static org.hamcrest.Matchers.is; |
... | @@ -52,7 +52,7 @@ public class GossipIntentStoreTest { | ... | @@ -52,7 +52,7 @@ public class GossipIntentStoreTest { |
52 | public void setUp() { | 52 | public void setUp() { |
53 | intentStore = new GossipIntentStore(); | 53 | intentStore = new GossipIntentStore(); |
54 | intentStore.storageService = new TestStorageService(); | 54 | intentStore.storageService = new TestStorageService(); |
55 | - intentStore.partitionService = new IntentPartitionServiceAdapter(); | 55 | + intentStore.partitionService = new WorkPartitionServiceAdapter(); |
56 | intentStore.clusterService = new ClusterServiceAdapter(); | 56 | intentStore.clusterService = new ClusterServiceAdapter(); |
57 | idGenerator = new MockIdGenerator(); | 57 | idGenerator = new MockIdGenerator(); |
58 | Intent.bindIdGenerator(idGenerator); | 58 | Intent.bindIdGenerator(idGenerator); | ... | ... |
... | @@ -50,9 +50,9 @@ import static org.easymock.EasyMock.verify; | ... | @@ -50,9 +50,9 @@ import static org.easymock.EasyMock.verify; |
50 | import static org.junit.Assert.assertTrue; | 50 | import static org.junit.Assert.assertTrue; |
51 | 51 | ||
52 | /** | 52 | /** |
53 | - * Unit tests for the IntentPartitionManager class. | 53 | + * Unit tests for the WorkPartitionManager class. |
54 | */ | 54 | */ |
55 | -public class IntentPartitionManagerTest { | 55 | +public class WorkPartitionManagerTest { |
56 | 56 | ||
57 | private final LeadershipEvent event | 57 | private final LeadershipEvent event |
58 | = new LeadershipEvent(LeadershipEvent.Type.CANDIDATES_CHANGED, | 58 | = new LeadershipEvent(LeadershipEvent.Type.CANDIDATES_CHANGED, |
... | @@ -64,12 +64,12 @@ public class IntentPartitionManagerTest { | ... | @@ -64,12 +64,12 @@ public class IntentPartitionManagerTest { |
64 | private static final NodeId OTHER_NODE_ID = new NodeId("other"); | 64 | private static final NodeId OTHER_NODE_ID = new NodeId("other"); |
65 | private static final NodeId INACTIVE_NODE_ID = new NodeId("inactive"); | 65 | private static final NodeId INACTIVE_NODE_ID = new NodeId("inactive"); |
66 | 66 | ||
67 | - private static final String ELECTION_PREFIX = "intent-partition-"; | 67 | + private static final String ELECTION_PREFIX = "work-partition-"; |
68 | 68 | ||
69 | private LeadershipService leadershipService; | 69 | private LeadershipService leadershipService; |
70 | private LeadershipEventListener leaderListener; | 70 | private LeadershipEventListener leaderListener; |
71 | 71 | ||
72 | - private IntentPartitionManager partitionManager; | 72 | + private WorkPartitionManager partitionManager; |
73 | 73 | ||
74 | @Before | 74 | @Before |
75 | public void setUp() { | 75 | public void setUp() { |
... | @@ -77,13 +77,13 @@ public class IntentPartitionManagerTest { | ... | @@ -77,13 +77,13 @@ public class IntentPartitionManagerTest { |
77 | 77 | ||
78 | leadershipService.addListener(anyObject(LeadershipEventListener.class)); | 78 | leadershipService.addListener(anyObject(LeadershipEventListener.class)); |
79 | expectLastCall().andDelegateTo(new TestLeadershipService()); | 79 | expectLastCall().andDelegateTo(new TestLeadershipService()); |
80 | - for (int i = 0; i < IntentPartitionManager.NUM_PARTITIONS; i++) { | 80 | + for (int i = 0; i < WorkPartitionManager.NUM_PARTITIONS; i++) { |
81 | expect(leadershipService.runForLeadership(ELECTION_PREFIX + i)) | 81 | expect(leadershipService.runForLeadership(ELECTION_PREFIX + i)) |
82 | .andReturn(null) | 82 | .andReturn(null) |
83 | .times(1); | 83 | .times(1); |
84 | } | 84 | } |
85 | 85 | ||
86 | - partitionManager = new IntentPartitionManager() | 86 | + partitionManager = new WorkPartitionManager() |
87 | .withScheduledExecutor(new NullScheduledExecutor()); | 87 | .withScheduledExecutor(new NullScheduledExecutor()); |
88 | 88 | ||
89 | partitionManager.clusterService = new TestClusterService(); | 89 | partitionManager.clusterService = new TestClusterService(); |
... | @@ -109,14 +109,14 @@ public class IntentPartitionManagerTest { | ... | @@ -109,14 +109,14 @@ public class IntentPartitionManagerTest { |
109 | .anyTimes(); | 109 | .anyTimes(); |
110 | } | 110 | } |
111 | 111 | ||
112 | - for (int i = numMine; i < IntentPartitionManager.NUM_PARTITIONS; i++) { | 112 | + for (int i = numMine; i < WorkPartitionManager.NUM_PARTITIONS; i++) { |
113 | expect(leadershipService.getLeadership(ELECTION_PREFIX + i)) | 113 | expect(leadershipService.getLeadership(ELECTION_PREFIX + i)) |
114 | .andReturn(new Leadership(ELECTION_PREFIX + i, | 114 | .andReturn(new Leadership(ELECTION_PREFIX + i, |
115 | new Leader(OTHER_NODE_ID, 1, 1000), | 115 | new Leader(OTHER_NODE_ID, 1, 1000), |
116 | allNodes)) | 116 | allNodes)) |
117 | .anyTimes(); | 117 | .anyTimes(); |
118 | } | 118 | } |
119 | - for (int i = 0; i < IntentPartitionManager.NUM_PARTITIONS; i++) { | 119 | + for (int i = 0; i < WorkPartitionManager.NUM_PARTITIONS; i++) { |
120 | expect(leadershipService.getCandidates(ELECTION_PREFIX + i)) | 120 | expect(leadershipService.getCandidates(ELECTION_PREFIX + i)) |
121 | .andReturn(Arrays.asList(MY_NODE_ID, OTHER_NODE_ID)) | 121 | .andReturn(Arrays.asList(MY_NODE_ID, OTHER_NODE_ID)) |
122 | .anyTimes(); | 122 | .anyTimes(); |
... | @@ -133,7 +133,7 @@ public class IntentPartitionManagerTest { | ... | @@ -133,7 +133,7 @@ public class IntentPartitionManagerTest { |
133 | 133 | ||
134 | leadershipService.addListener(anyObject(LeadershipEventListener.class)); | 134 | leadershipService.addListener(anyObject(LeadershipEventListener.class)); |
135 | 135 | ||
136 | - for (int i = 0; i < IntentPartitionManager.NUM_PARTITIONS; i++) { | 136 | + for (int i = 0; i < WorkPartitionManager.NUM_PARTITIONS; i++) { |
137 | expect(leadershipService.runForLeadership(ELECTION_PREFIX + i)) | 137 | expect(leadershipService.runForLeadership(ELECTION_PREFIX + i)) |
138 | .andReturn(null) | 138 | .andReturn(null) |
139 | .times(1); | 139 | .times(1); |
... | @@ -159,20 +159,20 @@ public class IntentPartitionManagerTest { | ... | @@ -159,20 +159,20 @@ public class IntentPartitionManagerTest { |
159 | Key myKey = new ControllableHashKey(0); | 159 | Key myKey = new ControllableHashKey(0); |
160 | Key notMyKey = new ControllableHashKey(1); | 160 | Key notMyKey = new ControllableHashKey(1); |
161 | 161 | ||
162 | - assertTrue(partitionManager.isMine(myKey)); | 162 | + assertTrue(partitionManager.isMine(myKey, Key::hash)); |
163 | - assertFalse(partitionManager.isMine(notMyKey)); | 163 | + assertFalse(partitionManager.isMine(notMyKey, Key::hash)); |
164 | 164 | ||
165 | // Make us the owner of 4 partitions now | 165 | // Make us the owner of 4 partitions now |
166 | reset(leadershipService); | 166 | reset(leadershipService); |
167 | setUpLeadershipService(4); | 167 | setUpLeadershipService(4); |
168 | replay(leadershipService); | 168 | replay(leadershipService); |
169 | 169 | ||
170 | - assertTrue(partitionManager.isMine(myKey)); | 170 | + assertTrue(partitionManager.isMine(myKey, Key::hash)); |
171 | // notMyKey is now my key because because we're in control of that | 171 | // notMyKey is now my key because because we're in control of that |
172 | // partition now | 172 | // partition now |
173 | - assertTrue(partitionManager.isMine(notMyKey)); | 173 | + assertTrue(partitionManager.isMine(notMyKey, Key::hash)); |
174 | 174 | ||
175 | - assertFalse(partitionManager.isMine(new ControllableHashKey(4))); | 175 | + assertFalse(partitionManager.isMine(new ControllableHashKey(4), Key::hash)); |
176 | } | 176 | } |
177 | 177 | ||
178 | /** | 178 | /** |
... | @@ -183,7 +183,7 @@ public class IntentPartitionManagerTest { | ... | @@ -183,7 +183,7 @@ public class IntentPartitionManagerTest { |
183 | @Test | 183 | @Test |
184 | public void testRebalanceScheduling() { | 184 | public void testRebalanceScheduling() { |
185 | // We have all the partitions so we'll need to relinquish some | 185 | // We have all the partitions so we'll need to relinquish some |
186 | - setUpLeadershipService(IntentPartitionManager.NUM_PARTITIONS); | 186 | + setUpLeadershipService(WorkPartitionManager.NUM_PARTITIONS); |
187 | 187 | ||
188 | replay(leadershipService); | 188 | replay(leadershipService); |
189 | 189 | ||
... | @@ -202,7 +202,7 @@ public class IntentPartitionManagerTest { | ... | @@ -202,7 +202,7 @@ public class IntentPartitionManagerTest { |
202 | @Test | 202 | @Test |
203 | public void testRebalance() { | 203 | public void testRebalance() { |
204 | // We have all the partitions so we'll need to relinquish some | 204 | // We have all the partitions so we'll need to relinquish some |
205 | - setUpLeadershipService(IntentPartitionManager.NUM_PARTITIONS); | 205 | + setUpLeadershipService(WorkPartitionManager.NUM_PARTITIONS); |
206 | 206 | ||
207 | leadershipService.withdraw(anyString()); | 207 | leadershipService.withdraw(anyString()); |
208 | expectLastCall().times(7); | 208 | expectLastCall().times(7); |
... | @@ -224,7 +224,7 @@ public class IntentPartitionManagerTest { | ... | @@ -224,7 +224,7 @@ public class IntentPartitionManagerTest { |
224 | @Test | 224 | @Test |
225 | public void testNoRebalance() { | 225 | public void testNoRebalance() { |
226 | // Partitions are already perfectly balanced among the two active instances | 226 | // Partitions are already perfectly balanced among the two active instances |
227 | - setUpLeadershipService(IntentPartitionManager.NUM_PARTITIONS / 2); | 227 | + setUpLeadershipService(WorkPartitionManager.NUM_PARTITIONS / 2); |
228 | replay(leadershipService); | 228 | replay(leadershipService); |
229 | 229 | ||
230 | partitionManager.activate(); | 230 | partitionManager.activate(); |
... | @@ -236,7 +236,7 @@ public class IntentPartitionManagerTest { | ... | @@ -236,7 +236,7 @@ public class IntentPartitionManagerTest { |
236 | 236 | ||
237 | reset(leadershipService); | 237 | reset(leadershipService); |
238 | // We have a smaller share than we should | 238 | // We have a smaller share than we should |
239 | - setUpLeadershipService(IntentPartitionManager.NUM_PARTITIONS / 2 - 1); | 239 | + setUpLeadershipService(WorkPartitionManager.NUM_PARTITIONS / 2 - 1); |
240 | replay(leadershipService); | 240 | replay(leadershipService); |
241 | 241 | ||
242 | // trigger rebalance | 242 | // trigger rebalance | ... | ... |
... | @@ -32,7 +32,7 @@ import org.onosproject.net.intent.Intent; | ... | @@ -32,7 +32,7 @@ import org.onosproject.net.intent.Intent; |
32 | import org.onosproject.net.intent.IntentData; | 32 | import org.onosproject.net.intent.IntentData; |
33 | import org.onosproject.net.intent.IntentEvent; | 33 | import org.onosproject.net.intent.IntentEvent; |
34 | import org.onosproject.net.intent.IntentListener; | 34 | import org.onosproject.net.intent.IntentListener; |
35 | -import org.onosproject.net.intent.IntentPartitionService; | 35 | +import org.onosproject.net.intent.WorkPartitionService; |
36 | import org.onosproject.net.intent.IntentService; | 36 | import org.onosproject.net.intent.IntentService; |
37 | import org.onosproject.net.intent.IntentState; | 37 | import org.onosproject.net.intent.IntentState; |
38 | import org.onosproject.net.intent.Key; | 38 | import org.onosproject.net.intent.Key; |
... | @@ -64,7 +64,7 @@ public class VirtualNetworkIntentService extends AbstractListenerManager<IntentE | ... | @@ -64,7 +64,7 @@ public class VirtualNetworkIntentService extends AbstractListenerManager<IntentE |
64 | 64 | ||
65 | protected IntentService intentService; | 65 | protected IntentService intentService; |
66 | protected VirtualNetworkStore store; | 66 | protected VirtualNetworkStore store; |
67 | - protected IntentPartitionService partitionService; | 67 | + protected WorkPartitionService partitionService; |
68 | 68 | ||
69 | private final VirtualNetwork network; | 69 | private final VirtualNetwork network; |
70 | private final VirtualNetworkService manager; | 70 | private final VirtualNetworkService manager; |
... | @@ -83,7 +83,7 @@ public class VirtualNetworkIntentService extends AbstractListenerManager<IntentE | ... | @@ -83,7 +83,7 @@ public class VirtualNetworkIntentService extends AbstractListenerManager<IntentE |
83 | this.manager = virtualNetworkManager; | 83 | this.manager = virtualNetworkManager; |
84 | this.store = serviceDirectory.get(VirtualNetworkStore.class); | 84 | this.store = serviceDirectory.get(VirtualNetworkStore.class); |
85 | this.intentService = serviceDirectory.get(IntentService.class); | 85 | this.intentService = serviceDirectory.get(IntentService.class); |
86 | - this.partitionService = serviceDirectory.get(IntentPartitionService.class); | 86 | + this.partitionService = serviceDirectory.get(WorkPartitionService.class); |
87 | } | 87 | } |
88 | 88 | ||
89 | @Override | 89 | @Override |
... | @@ -225,7 +225,7 @@ public class VirtualNetworkIntentService extends AbstractListenerManager<IntentE | ... | @@ -225,7 +225,7 @@ public class VirtualNetworkIntentService extends AbstractListenerManager<IntentE |
225 | checkNotNull(intentKey, INTENT_KEY_NULL); | 225 | checkNotNull(intentKey, INTENT_KEY_NULL); |
226 | Intent intent = getIntent(intentKey); | 226 | Intent intent = getIntent(intentKey); |
227 | checkNotNull(intent, INTENT_NULL); | 227 | checkNotNull(intent, INTENT_NULL); |
228 | - return partitionService.isMine(intentKey); | 228 | + return partitionService.isMine(intentKey, Key::hash); |
229 | } | 229 | } |
230 | 230 | ||
231 | @Override | 231 | @Override | ... | ... |
... | @@ -54,8 +54,8 @@ import org.onosproject.net.intent.IntentCompiler; | ... | @@ -54,8 +54,8 @@ import org.onosproject.net.intent.IntentCompiler; |
54 | import org.onosproject.net.intent.IntentEvent; | 54 | import org.onosproject.net.intent.IntentEvent; |
55 | import org.onosproject.net.intent.IntentExtensionService; | 55 | import org.onosproject.net.intent.IntentExtensionService; |
56 | import org.onosproject.net.intent.IntentListener; | 56 | import org.onosproject.net.intent.IntentListener; |
57 | -import org.onosproject.net.intent.IntentPartitionService; | 57 | +import org.onosproject.net.intent.WorkPartitionService; |
58 | -import org.onosproject.net.intent.IntentPartitionServiceAdapter; | 58 | +import org.onosproject.net.intent.WorkPartitionServiceAdapter; |
59 | import org.onosproject.net.intent.IntentService; | 59 | import org.onosproject.net.intent.IntentService; |
60 | import org.onosproject.net.intent.IntentState; | 60 | import org.onosproject.net.intent.IntentState; |
61 | import org.onosproject.net.intent.IntentTestsMocks; | 61 | import org.onosproject.net.intent.IntentTestsMocks; |
... | @@ -103,7 +103,7 @@ public class VirtualNetworkIntentServiceTest extends TestDeviceParams { | ... | @@ -103,7 +103,7 @@ public class VirtualNetworkIntentServiceTest extends TestDeviceParams { |
103 | private VirtualNetworkIntentService vnetIntentService; | 103 | private VirtualNetworkIntentService vnetIntentService; |
104 | private TestIntentCompiler compiler = new TestIntentCompiler(); | 104 | private TestIntentCompiler compiler = new TestIntentCompiler(); |
105 | private IntentExtensionService intentExtensionService; | 105 | private IntentExtensionService intentExtensionService; |
106 | - private IntentPartitionService intentPartitionService; | 106 | + private WorkPartitionService workPartitionService; |
107 | private ServiceDirectory testDirectory; | 107 | private ServiceDirectory testDirectory; |
108 | private TestListener listener = new TestListener(); | 108 | private TestListener listener = new TestListener(); |
109 | private IdGenerator idGenerator = new MockIdGenerator(); | 109 | private IdGenerator idGenerator = new MockIdGenerator(); |
... | @@ -142,11 +142,11 @@ public class VirtualNetworkIntentServiceTest extends TestDeviceParams { | ... | @@ -142,11 +142,11 @@ public class VirtualNetworkIntentServiceTest extends TestDeviceParams { |
142 | withdrawn = new Semaphore(0, true); | 142 | withdrawn = new Semaphore(0, true); |
143 | purged = new Semaphore(0, true); | 143 | purged = new Semaphore(0, true); |
144 | 144 | ||
145 | - intentPartitionService = new IntentPartitionServiceAdapter(); | 145 | + workPartitionService = new WorkPartitionServiceAdapter(); |
146 | testDirectory = new TestServiceDirectory() | 146 | testDirectory = new TestServiceDirectory() |
147 | .add(VirtualNetworkStore.class, virtualNetworkManagerStore) | 147 | .add(VirtualNetworkStore.class, virtualNetworkManagerStore) |
148 | .add(IntentService.class, intentService) | 148 | .add(IntentService.class, intentService) |
149 | - .add(IntentPartitionService.class, intentPartitionService); | 149 | + .add(WorkPartitionService.class, workPartitionService); |
150 | BaseResource.setServiceDirectory(testDirectory); | 150 | BaseResource.setServiceDirectory(testDirectory); |
151 | } | 151 | } |
152 | 152 | ||
... | @@ -215,7 +215,7 @@ public class VirtualNetworkIntentServiceTest extends TestDeviceParams { | ... | @@ -215,7 +215,7 @@ public class VirtualNetworkIntentServiceTest extends TestDeviceParams { |
215 | vnetIntentService = new VirtualNetworkIntentService(manager, virtualNetwork, testDirectory); | 215 | vnetIntentService = new VirtualNetworkIntentService(manager, virtualNetwork, testDirectory); |
216 | vnetIntentService.intentService = intentService; | 216 | vnetIntentService.intentService = intentService; |
217 | vnetIntentService.store = virtualNetworkManagerStore; | 217 | vnetIntentService.store = virtualNetworkManagerStore; |
218 | - vnetIntentService.partitionService = intentPartitionService; | 218 | + vnetIntentService.partitionService = workPartitionService; |
219 | return virtualNetwork; | 219 | return virtualNetwork; |
220 | } | 220 | } |
221 | 221 | ... | ... |
-
Please register or login to post a comment