Sho SHIMIZU

Make IntentManager configurable to tell test mode

This is a quick fix for ONOS-3923, not a long-term solution.

Change-Id: I56e8af57de37e6db1f5e2355d5bb60372adc83f6
...@@ -18,6 +18,8 @@ package org.onosproject.net.intent.impl; ...@@ -18,6 +18,8 @@ package org.onosproject.net.intent.impl;
18 import org.apache.felix.scr.annotations.Activate; 18 import org.apache.felix.scr.annotations.Activate;
19 import org.apache.felix.scr.annotations.Component; 19 import org.apache.felix.scr.annotations.Component;
20 import org.apache.felix.scr.annotations.Deactivate; 20 import org.apache.felix.scr.annotations.Deactivate;
21 +import org.apache.felix.scr.annotations.Modified;
22 +import org.apache.felix.scr.annotations.Property;
21 import org.apache.felix.scr.annotations.Reference; 23 import org.apache.felix.scr.annotations.Reference;
22 import org.apache.felix.scr.annotations.ReferenceCardinality; 24 import org.apache.felix.scr.annotations.ReferenceCardinality;
23 import org.apache.felix.scr.annotations.Service; 25 import org.apache.felix.scr.annotations.Service;
...@@ -42,6 +44,7 @@ import org.onosproject.net.intent.Key; ...@@ -42,6 +44,7 @@ import org.onosproject.net.intent.Key;
42 import org.onosproject.net.intent.impl.phase.FinalIntentProcessPhase; 44 import org.onosproject.net.intent.impl.phase.FinalIntentProcessPhase;
43 import org.onosproject.net.intent.impl.phase.IntentProcessPhase; 45 import org.onosproject.net.intent.impl.phase.IntentProcessPhase;
44 import org.onosproject.net.newresource.ResourceService; 46 import org.onosproject.net.newresource.ResourceService;
47 +import org.osgi.service.component.ComponentContext;
45 import org.slf4j.Logger; 48 import org.slf4j.Logger;
46 49
47 import java.util.Collection; 50 import java.util.Collection;
...@@ -55,6 +58,7 @@ import java.util.concurrent.ExecutorService; ...@@ -55,6 +58,7 @@ import java.util.concurrent.ExecutorService;
55 import java.util.stream.Collectors; 58 import java.util.stream.Collectors;
56 59
57 import static com.google.common.base.Preconditions.checkNotNull; 60 import static com.google.common.base.Preconditions.checkNotNull;
61 +import static com.google.common.base.Strings.isNullOrEmpty;
58 import static java.util.concurrent.Executors.newFixedThreadPool; 62 import static java.util.concurrent.Executors.newFixedThreadPool;
59 import static java.util.concurrent.Executors.newSingleThreadExecutor; 63 import static java.util.concurrent.Executors.newSingleThreadExecutor;
60 import static org.onlab.util.Tools.groupedThreads; 64 import static org.onlab.util.Tools.groupedThreads;
...@@ -86,6 +90,12 @@ public class IntentManager ...@@ -86,6 +90,12 @@ public class IntentManager
86 = EnumSet.of(INSTALL_REQ, FAILED, WITHDRAW_REQ); 90 = EnumSet.of(INSTALL_REQ, FAILED, WITHDRAW_REQ);
87 private static final EnumSet<IntentState> WITHDRAW 91 private static final EnumSet<IntentState> WITHDRAW
88 = EnumSet.of(WITHDRAW_REQ, WITHDRAWING, WITHDRAWN); 92 = EnumSet.of(WITHDRAW_REQ, WITHDRAWING, WITHDRAWN);
93 + private static final boolean DEFAULT_SKIP_RELEASE_RESOURCES_ON_WITHDRAWAL = false;
94 +
95 + @Property(name = "skipReleaseResourcesOnWithdrawal",
96 + boolValue = DEFAULT_SKIP_RELEASE_RESOURCES_ON_WITHDRAWAL,
97 + label = "Indicates whether skipping resource releases on withdrawal is enabled or not")
98 + private boolean skipReleaseResourcesOnWithdrawal = DEFAULT_SKIP_RELEASE_RESOURCES_ON_WITHDRAWAL;
89 99
90 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) 100 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
91 protected CoreService coreService; 101 protected CoreService coreService;
...@@ -112,6 +122,7 @@ public class IntentManager ...@@ -112,6 +122,7 @@ public class IntentManager
112 private final CompilerRegistry compilerRegistry = new CompilerRegistry(); 122 private final CompilerRegistry compilerRegistry = new CompilerRegistry();
113 private final InternalIntentProcessor processor = new InternalIntentProcessor(); 123 private final InternalIntentProcessor processor = new InternalIntentProcessor();
114 private final IntentStoreDelegate delegate = new InternalStoreDelegate(); 124 private final IntentStoreDelegate delegate = new InternalStoreDelegate();
125 + private final IntentStoreDelegate testOnlyDelegate = new TestOnlyIntentStoreDelegate();
115 private final TopologyChangeDelegate topoDelegate = new InternalTopoChangeDelegate(); 126 private final TopologyChangeDelegate topoDelegate = new InternalTopoChangeDelegate();
116 private final IntentBatchDelegate batchDelegate = new InternalBatchDelegate(); 127 private final IntentBatchDelegate batchDelegate = new InternalBatchDelegate();
117 private IdGenerator idGenerator; 128 private IdGenerator idGenerator;
...@@ -121,7 +132,11 @@ public class IntentManager ...@@ -121,7 +132,11 @@ public class IntentManager
121 @Activate 132 @Activate
122 public void activate() { 133 public void activate() {
123 intentInstaller.init(store, trackerService, flowRuleService, flowObjectiveService); 134 intentInstaller.init(store, trackerService, flowRuleService, flowObjectiveService);
124 - store.setDelegate(delegate); 135 + if (skipReleaseResourcesOnWithdrawal) {
136 + store.setDelegate(testOnlyDelegate);
137 + } else {
138 + store.setDelegate(delegate);
139 + }
125 trackerService.setDelegate(topoDelegate); 140 trackerService.setDelegate(topoDelegate);
126 eventDispatcher.addSink(IntentEvent.class, listenerRegistry); 141 eventDispatcher.addSink(IntentEvent.class, listenerRegistry);
127 batchExecutor = newSingleThreadExecutor(groupedThreads("onos/intent", "batch")); 142 batchExecutor = newSingleThreadExecutor(groupedThreads("onos/intent", "batch"));
...@@ -134,7 +149,11 @@ public class IntentManager ...@@ -134,7 +149,11 @@ public class IntentManager
134 @Deactivate 149 @Deactivate
135 public void deactivate() { 150 public void deactivate() {
136 intentInstaller.init(null, null, null, null); 151 intentInstaller.init(null, null, null, null);
137 - store.unsetDelegate(delegate); 152 + if (skipReleaseResourcesOnWithdrawal) {
153 + store.unsetDelegate(testOnlyDelegate);
154 + } else {
155 + store.unsetDelegate(delegate);
156 + }
138 trackerService.unsetDelegate(topoDelegate); 157 trackerService.unsetDelegate(topoDelegate);
139 eventDispatcher.removeSink(IntentEvent.class); 158 eventDispatcher.removeSink(IntentEvent.class);
140 batchExecutor.shutdown(); 159 batchExecutor.shutdown();
...@@ -143,6 +162,31 @@ public class IntentManager ...@@ -143,6 +162,31 @@ public class IntentManager
143 log.info("Stopped"); 162 log.info("Stopped");
144 } 163 }
145 164
165 + @Modified
166 + public void modified(ComponentContext context) {
167 + if (context == null) {
168 + skipReleaseResourcesOnWithdrawal = DEFAULT_SKIP_RELEASE_RESOURCES_ON_WITHDRAWAL;
169 + logConfig("Default config");
170 + return;
171 + }
172 +
173 + String s = Tools.get(context.getProperties(), "skipReleaseResourcesOnWithdrawal");
174 + boolean newTestEnabled = isNullOrEmpty(s) ? skipReleaseResourcesOnWithdrawal : Boolean.parseBoolean(s.trim());
175 + if (skipReleaseResourcesOnWithdrawal && !newTestEnabled) {
176 + store.unsetDelegate(testOnlyDelegate);
177 + store.setDelegate(delegate);
178 + logConfig("Reconfigured");
179 + } else if (!skipReleaseResourcesOnWithdrawal && newTestEnabled) {
180 + store.unsetDelegate(delegate);
181 + store.setDelegate(testOnlyDelegate);
182 + logConfig("Reconfigured");
183 + }
184 + }
185 +
186 + private void logConfig(String prefix) {
187 + log.info("{} with skipReleaseResourcesOnWithdrawal = {}", prefix, skipReleaseResourcesOnWithdrawal);
188 + }
189 +
146 @Override 190 @Override
147 public void submit(Intent intent) { 191 public void submit(Intent intent) {
148 checkPermission(INTENT_WRITE); 192 checkPermission(INTENT_WRITE);
...@@ -261,6 +305,24 @@ public class IntentManager ...@@ -261,6 +305,24 @@ public class IntentManager
261 } 305 }
262 } 306 }
263 307
308 + // Store delegate enabled only when performing intent throughput tests
309 + private class TestOnlyIntentStoreDelegate implements IntentStoreDelegate {
310 + @Override
311 + public void process(IntentData data) {
312 + accumulator.add(data);
313 + }
314 +
315 + @Override
316 + public void onUpdate(IntentData data) {
317 + trackerService.trackIntent(data);
318 + }
319 +
320 + @Override
321 + public void notify(IntentEvent event) {
322 + post(event);
323 + }
324 + }
325 +
264 private void buildAndSubmitBatches(Iterable<Key> intentKeys, 326 private void buildAndSubmitBatches(Iterable<Key> intentKeys,
265 boolean compileAllFailed) { 327 boolean compileAllFailed) {
266 // Attempt recompilation of the specified intents first. 328 // Attempt recompilation of the specified intents first.
......