Pingping Lin
Committed by Gerrit Code Review

when deactivate sdn-ip, also delete all relative intents

Change-Id: I7a6bd64b5a9525dc49ca2b9353fcc45dc9a16288
...@@ -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 - // 103 + }
102 - // Withdraw all app related intents 104 + }
103 - //
104 - if (!isElectedLeader) {
105 - return; // Nothing to do: not the leader anymore
106 - }
107 105
108 - // 106 + /**
109 - // NOTE: We don't withdraw the intents during shutdown, because 107 + * Withdraws all intents.
110 - // it creates flux in the data plane during switchover. 108 + */
111 - // 109 + public void removeIntents() {
112 - 110 + if (!isElectedLeader) {
113 - /* 111 + // only leader will withdraw intents
114 - // 112 + return;
115 - // Build a batch operation to withdraw all intents from this 113 + }
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 - }
126 114
127 - // Skip the intents that are already withdrawn 115 + log.debug("Intent Synchronizer shutdown: withdrawing all intents...");
128 - IntentState intentState =
129 - intentService.getIntentState(intent.id());
130 - if ((intentState == null) ||
131 - intentState.equals(IntentState.WITHDRAWING) ||
132 - intentState.equals(IntentState.WITHDRAWN)) {
133 - continue;
134 - }
135 116
136 - log.trace("Intent Synchronizer withdrawing intent: {}", 117 + for (Entry<Key, Intent> entry : intents.entrySet()) {
137 - intent); 118 + intentService.withdraw(entry.getValue());
138 - builder.addWithdrawOperation(intent.id()); 119 + log.debug("Intent Synchronizer withdrawing intent: {}",
139 - } 120 + entry.getValue());
140 - IntentOperations intentOperations = builder.build();
141 - intentService.execute(intentOperations);
142 - leaderChanged(false);
143 -
144 - peerIntents.clear();
145 - routeIntents.clear();
146 - log.debug("Intent Synchronizer shutdown completed");
147 - */
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)
...@@ -84,7 +88,7 @@ public class SdnIp implements SdnIpService { ...@@ -84,7 +88,7 @@ public class SdnIp implements SdnIpService {
84 private SdnIpFib fib; 88 private SdnIpFib fib;
85 89
86 private LeadershipEventListener leadershipEventListener = 90 private LeadershipEventListener leadershipEventListener =
87 - new InnerLeadershipEventListener(); 91 + new InnerLeadershipEventListener();
88 private ApplicationId appId; 92 private ApplicationId appId;
89 private ControllerNode localControllerNode; 93 private ControllerNode localControllerNode;
90 94
...@@ -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
......