Committed by
Gerrit Code Review
when deactivate sdn-ip, also delete all relative intents
Change-Id: I7a6bd64b5a9525dc49ca2b9353fcc45dc9a16288
Showing
2 changed files
with
40 additions
and
57 deletions
... | @@ -15,24 +15,25 @@ | ... | @@ -15,24 +15,25 @@ |
15 | */ | 15 | */ |
16 | package org.onosproject.sdnip; | 16 | package org.onosproject.sdnip; |
17 | 17 | ||
18 | -import org.onosproject.core.ApplicationId; | 18 | +import static java.util.concurrent.Executors.newSingleThreadExecutor; |
19 | -import org.onosproject.net.intent.Intent; | 19 | +import static org.onlab.util.Tools.groupedThreads; |
20 | -import org.onosproject.net.intent.IntentService; | ||
21 | -import org.onosproject.net.intent.IntentState; | ||
22 | -import org.onosproject.net.intent.Key; | ||
23 | -import org.onosproject.routing.IntentSynchronizationService; | ||
24 | -import org.slf4j.Logger; | ||
25 | -import org.slf4j.LoggerFactory; | ||
26 | 20 | ||
27 | import java.util.HashMap; | 21 | import java.util.HashMap; |
28 | import java.util.LinkedList; | 22 | import java.util.LinkedList; |
29 | import java.util.List; | 23 | import java.util.List; |
30 | import java.util.Map; | 24 | import java.util.Map; |
25 | +import java.util.Map.Entry; | ||
31 | import java.util.concurrent.ConcurrentHashMap; | 26 | import java.util.concurrent.ConcurrentHashMap; |
32 | import java.util.concurrent.ExecutorService; | 27 | import java.util.concurrent.ExecutorService; |
33 | 28 | ||
34 | -import static java.util.concurrent.Executors.newSingleThreadExecutor; | 29 | +import org.onosproject.core.ApplicationId; |
35 | -import static org.onlab.util.Tools.groupedThreads; | 30 | +import org.onosproject.net.intent.Intent; |
31 | +import org.onosproject.net.intent.IntentService; | ||
32 | +import org.onosproject.net.intent.IntentState; | ||
33 | +import org.onosproject.net.intent.Key; | ||
34 | +import org.onosproject.routing.IntentSynchronizationService; | ||
35 | +import org.slf4j.Logger; | ||
36 | +import org.slf4j.LoggerFactory; | ||
36 | 37 | ||
37 | /** | 38 | /** |
38 | * Synchronizes intents between the in-memory intent store and the | 39 | * Synchronizes intents between the in-memory intent store and the |
... | @@ -97,55 +98,30 @@ public class IntentSynchronizer implements IntentSynchronizationService { | ... | @@ -97,55 +98,30 @@ public class IntentSynchronizer implements IntentSynchronizationService { |
97 | synchronized (this) { | 98 | synchronized (this) { |
98 | // Stop the thread(s) | 99 | // Stop the thread(s) |
99 | intentsSynchronizerExecutor.shutdownNow(); | 100 | intentsSynchronizerExecutor.shutdownNow(); |
101 | + log.info("Intents Synchronizer Executor shutdown completed"); | ||
100 | 102 | ||
101 | - // | ||
102 | - // Withdraw all app related intents | ||
103 | - // | ||
104 | - if (!isElectedLeader) { | ||
105 | - return; // Nothing to do: not the leader anymore | ||
106 | } | 103 | } |
107 | - | ||
108 | - // | ||
109 | - // NOTE: We don't withdraw the intents during shutdown, because | ||
110 | - // it creates flux in the data plane during switchover. | ||
111 | - // | ||
112 | - | ||
113 | - /* | ||
114 | - // | ||
115 | - // Build a batch operation to withdraw all intents from this | ||
116 | - // application. | ||
117 | - // | ||
118 | - log.debug("Intent Synchronizer shutdown: " + | ||
119 | - "withdrawing all intents..."); | ||
120 | - IntentOperations.Builder builder = IntentOperations.builder(appId); | ||
121 | - for (Intent intent : intentService.getIntents()) { | ||
122 | - // Skip the intents from other applications | ||
123 | - if (!intent.appId().equals(appId)) { | ||
124 | - continue; | ||
125 | } | 104 | } |
126 | 105 | ||
127 | - // Skip the intents that are already withdrawn | 106 | + /** |
128 | - IntentState intentState = | 107 | + * Withdraws all intents. |
129 | - intentService.getIntentState(intent.id()); | 108 | + */ |
130 | - if ((intentState == null) || | 109 | + public void removeIntents() { |
131 | - intentState.equals(IntentState.WITHDRAWING) || | 110 | + if (!isElectedLeader) { |
132 | - intentState.equals(IntentState.WITHDRAWN)) { | 111 | + // only leader will withdraw intents |
133 | - continue; | 112 | + return; |
134 | } | 113 | } |
135 | 114 | ||
136 | - log.trace("Intent Synchronizer withdrawing intent: {}", | 115 | + log.debug("Intent Synchronizer shutdown: withdrawing all intents..."); |
137 | - intent); | ||
138 | - builder.addWithdrawOperation(intent.id()); | ||
139 | - } | ||
140 | - IntentOperations intentOperations = builder.build(); | ||
141 | - intentService.execute(intentOperations); | ||
142 | - leaderChanged(false); | ||
143 | 116 | ||
144 | - peerIntents.clear(); | 117 | + for (Entry<Key, Intent> entry : intents.entrySet()) { |
145 | - routeIntents.clear(); | 118 | + intentService.withdraw(entry.getValue()); |
146 | - log.debug("Intent Synchronizer shutdown completed"); | 119 | + log.debug("Intent Synchronizer withdrawing intent: {}", |
147 | - */ | 120 | + entry.getValue()); |
148 | } | 121 | } |
122 | + | ||
123 | + intents.clear(); | ||
124 | + log.info("Tried to clean all intents"); | ||
149 | } | 125 | } |
150 | 126 | ||
151 | @Override | 127 | @Override |
... | @@ -261,5 +237,4 @@ public class IntentSynchronizer implements IntentSynchronizationService { | ... | @@ -261,5 +237,4 @@ public class IntentSynchronizer implements IntentSynchronizationService { |
261 | } | 237 | } |
262 | log.debug("Intent synchronization completed"); | 238 | log.debug("Intent synchronization completed"); |
263 | } | 239 | } |
264 | - | ||
265 | } | 240 | } | ... | ... |
... | @@ -15,12 +15,17 @@ | ... | @@ -15,12 +15,17 @@ |
15 | */ | 15 | */ |
16 | package org.onosproject.sdnip; | 16 | package org.onosproject.sdnip; |
17 | 17 | ||
18 | +import static org.slf4j.LoggerFactory.getLogger; | ||
19 | + | ||
20 | +import java.util.Objects; | ||
21 | + | ||
18 | import org.apache.felix.scr.annotations.Activate; | 22 | import org.apache.felix.scr.annotations.Activate; |
19 | import org.apache.felix.scr.annotations.Component; | 23 | import org.apache.felix.scr.annotations.Component; |
20 | import org.apache.felix.scr.annotations.Deactivate; | 24 | import org.apache.felix.scr.annotations.Deactivate; |
21 | import org.apache.felix.scr.annotations.Reference; | 25 | import org.apache.felix.scr.annotations.Reference; |
22 | import org.apache.felix.scr.annotations.ReferenceCardinality; | 26 | import org.apache.felix.scr.annotations.ReferenceCardinality; |
23 | import org.apache.felix.scr.annotations.Service; | 27 | import org.apache.felix.scr.annotations.Service; |
28 | +import org.onosproject.app.ApplicationService; | ||
24 | import org.onosproject.cluster.ClusterService; | 29 | import org.onosproject.cluster.ClusterService; |
25 | import org.onosproject.cluster.ControllerNode; | 30 | import org.onosproject.cluster.ControllerNode; |
26 | import org.onosproject.cluster.LeadershipEvent; | 31 | import org.onosproject.cluster.LeadershipEvent; |
... | @@ -28,8 +33,8 @@ import org.onosproject.cluster.LeadershipEventListener; | ... | @@ -28,8 +33,8 @@ import org.onosproject.cluster.LeadershipEventListener; |
28 | import org.onosproject.cluster.LeadershipService; | 33 | import org.onosproject.cluster.LeadershipService; |
29 | import org.onosproject.core.ApplicationId; | 34 | import org.onosproject.core.ApplicationId; |
30 | import org.onosproject.core.CoreService; | 35 | import org.onosproject.core.CoreService; |
31 | -import org.onosproject.net.config.NetworkConfigService; | ||
32 | import org.onosproject.incubator.net.intf.InterfaceService; | 36 | import org.onosproject.incubator.net.intf.InterfaceService; |
37 | +import org.onosproject.net.config.NetworkConfigService; | ||
33 | import org.onosproject.net.host.HostService; | 38 | import org.onosproject.net.host.HostService; |
34 | import org.onosproject.net.intent.IntentService; | 39 | import org.onosproject.net.intent.IntentService; |
35 | import org.onosproject.routing.IntentSynchronizationService; | 40 | import org.onosproject.routing.IntentSynchronizationService; |
... | @@ -38,10 +43,6 @@ import org.onosproject.routing.SdnIpService; | ... | @@ -38,10 +43,6 @@ import org.onosproject.routing.SdnIpService; |
38 | import org.onosproject.routing.config.RoutingConfigurationService; | 43 | import org.onosproject.routing.config.RoutingConfigurationService; |
39 | import org.slf4j.Logger; | 44 | import org.slf4j.Logger; |
40 | 45 | ||
41 | -import java.util.Objects; | ||
42 | - | ||
43 | -import static org.slf4j.LoggerFactory.getLogger; | ||
44 | - | ||
45 | /** | 46 | /** |
46 | * Component for the SDN-IP peering application. | 47 | * Component for the SDN-IP peering application. |
47 | */ | 48 | */ |
... | @@ -59,6 +60,9 @@ public class SdnIp implements SdnIpService { | ... | @@ -59,6 +60,9 @@ public class SdnIp implements SdnIpService { |
59 | protected IntentService intentService; | 60 | protected IntentService intentService; |
60 | 61 | ||
61 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) | 62 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
63 | + protected ApplicationService applicationService; | ||
64 | + | ||
65 | + @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) | ||
62 | protected HostService hostService; | 66 | protected HostService hostService; |
63 | 67 | ||
64 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) | 68 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
... | @@ -113,6 +117,10 @@ public class SdnIp implements SdnIpService { | ... | @@ -113,6 +117,10 @@ public class SdnIp implements SdnIpService { |
113 | 117 | ||
114 | leadershipService.addListener(leadershipEventListener); | 118 | leadershipService.addListener(leadershipEventListener); |
115 | leadershipService.runForLeadership(appId.name()); | 119 | leadershipService.runForLeadership(appId.name()); |
120 | + | ||
121 | + applicationService.registerDeactivateHook(appId, | ||
122 | + intentSynchronizer::removeIntents); | ||
123 | + | ||
116 | } | 124 | } |
117 | 125 | ||
118 | @Deactivate | 126 | @Deactivate | ... | ... |
-
Please register or login to post a comment