Thomas Vachuska | 4f1a60c | 2014-10-28 13:39:07 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2014 Open Networking Laboratory |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 16 | package org.onosproject.net.intent.impl; |
Brian O'Connor | 66630c8 | 2014-10-02 21:08:19 -0700 | [diff] [blame] | 17 | |
Brian O'Connor | 0e271dc | 2015-02-04 18:20:25 -0800 | [diff] [blame] | 18 | import com.google.common.collect.ImmutableList; |
| 19 | import com.google.common.collect.ImmutableMap; |
Brian O'Connor | 66630c8 | 2014-10-02 21:08:19 -0700 | [diff] [blame] | 20 | import org.apache.felix.scr.annotations.Activate; |
| 21 | import org.apache.felix.scr.annotations.Component; |
| 22 | import org.apache.felix.scr.annotations.Deactivate; |
| 23 | import org.apache.felix.scr.annotations.Reference; |
| 24 | import org.apache.felix.scr.annotations.ReferenceCardinality; |
| 25 | import org.apache.felix.scr.annotations.Service; |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 26 | import org.onosproject.core.CoreService; |
| 27 | import org.onosproject.core.IdGenerator; |
| 28 | import org.onosproject.event.AbstractListenerRegistry; |
| 29 | import org.onosproject.event.EventDeliveryService; |
Brian O'Connor | 7775bda | 2015-02-06 15:01:18 -0800 | [diff] [blame] | 30 | import org.onosproject.net.flow.FlowRule; |
| 31 | import org.onosproject.net.flow.FlowRuleBatchEntry; |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 32 | import org.onosproject.net.flow.FlowRuleBatchOperation; |
Brian O'Connor | 0e271dc | 2015-02-04 18:20:25 -0800 | [diff] [blame] | 33 | import org.onosproject.net.flow.FlowRuleOperations; |
Brian O'Connor | 7775bda | 2015-02-06 15:01:18 -0800 | [diff] [blame] | 34 | import org.onosproject.net.flow.FlowRuleOperationsContext; |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 35 | import org.onosproject.net.flow.FlowRuleService; |
| 36 | import org.onosproject.net.intent.Intent; |
| 37 | import org.onosproject.net.intent.IntentBatchDelegate; |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 38 | import org.onosproject.net.intent.IntentCompiler; |
Brian O'Connor | cff0332 | 2015-02-03 15:28:59 -0800 | [diff] [blame] | 39 | import org.onosproject.net.intent.IntentData; |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 40 | import org.onosproject.net.intent.IntentEvent; |
| 41 | import org.onosproject.net.intent.IntentException; |
| 42 | import org.onosproject.net.intent.IntentExtensionService; |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 43 | import org.onosproject.net.intent.IntentInstaller; |
| 44 | import org.onosproject.net.intent.IntentListener; |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 45 | import org.onosproject.net.intent.IntentService; |
| 46 | import org.onosproject.net.intent.IntentState; |
| 47 | import org.onosproject.net.intent.IntentStore; |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 48 | import org.onosproject.net.intent.IntentStoreDelegate; |
Ray Milkey | f9af43c | 2015-02-09 16:45:48 -0800 | [diff] [blame] | 49 | import org.onosproject.net.intent.Key; |
Brian O'Connor | 66630c8 | 2014-10-02 21:08:19 -0700 | [diff] [blame] | 50 | import org.slf4j.Logger; |
| 51 | |
Brian O'Connor | 0e271dc | 2015-02-04 18:20:25 -0800 | [diff] [blame] | 52 | import java.util.ArrayList; |
| 53 | import java.util.Collection; |
Ray Milkey | 9f74c08 | 2015-02-11 15:40:16 -0800 | [diff] [blame] | 54 | import java.util.Collections; |
Brian O'Connor | 0e271dc | 2015-02-04 18:20:25 -0800 | [diff] [blame] | 55 | import java.util.EnumSet; |
Brian O'Connor | 7775bda | 2015-02-06 15:01:18 -0800 | [diff] [blame] | 56 | import java.util.Iterator; |
Brian O'Connor | 0e271dc | 2015-02-04 18:20:25 -0800 | [diff] [blame] | 57 | import java.util.List; |
| 58 | import java.util.Map; |
| 59 | import java.util.Optional; |
| 60 | import java.util.concurrent.Callable; |
| 61 | import java.util.concurrent.ConcurrentHashMap; |
| 62 | import java.util.concurrent.ConcurrentMap; |
| 63 | import java.util.concurrent.ExecutionException; |
| 64 | import java.util.concurrent.ExecutorService; |
| 65 | import java.util.concurrent.Future; |
| 66 | import java.util.stream.Collectors; |
Brian O'Connor | fa81eae | 2014-10-30 13:20:05 -0700 | [diff] [blame] | 67 | |
Brian O'Connor | fa81eae | 2014-10-30 13:20:05 -0700 | [diff] [blame] | 68 | import static com.google.common.base.Preconditions.checkNotNull; |
Yuta HIGUCHI | c2bf3d8 | 2014-11-28 18:50:41 -0800 | [diff] [blame] | 69 | import static java.util.concurrent.Executors.newFixedThreadPool; |
Brian O'Connor | db15b04 | 2015-02-04 14:59:28 -0800 | [diff] [blame] | 70 | import static java.util.concurrent.Executors.newSingleThreadExecutor; |
Brian O'Connor | fa81eae | 2014-10-30 13:20:05 -0700 | [diff] [blame] | 71 | import static org.onlab.util.Tools.namedThreads; |
Brian O'Connor | 0e271dc | 2015-02-04 18:20:25 -0800 | [diff] [blame] | 72 | import static org.onosproject.net.intent.IntentState.*; |
Brian O'Connor | fa81eae | 2014-10-30 13:20:05 -0700 | [diff] [blame] | 73 | import static org.slf4j.LoggerFactory.getLogger; |
Brian O'Connor | 66630c8 | 2014-10-02 21:08:19 -0700 | [diff] [blame] | 74 | |
| 75 | /** |
| 76 | * An implementation of Intent Manager. |
| 77 | */ |
| 78 | @Component(immediate = true) |
| 79 | @Service |
| 80 | public class IntentManager |
| 81 | implements IntentService, IntentExtensionService { |
Sho SHIMIZU | 8b5051d | 2014-11-05 11:24:13 -0800 | [diff] [blame] | 82 | private static final Logger log = getLogger(IntentManager.class); |
Brian O'Connor | 66630c8 | 2014-10-02 21:08:19 -0700 | [diff] [blame] | 83 | |
| 84 | public static final String INTENT_NULL = "Intent cannot be null"; |
Ray Milkey | f9af43c | 2015-02-09 16:45:48 -0800 | [diff] [blame] | 85 | public static final String INTENT_ID_NULL = "Intent key cannot be null"; |
Brian O'Connor | 66630c8 | 2014-10-02 21:08:19 -0700 | [diff] [blame] | 86 | |
Yuta HIGUCHI | c2bf3d8 | 2014-11-28 18:50:41 -0800 | [diff] [blame] | 87 | private static final int NUM_THREADS = 12; |
| 88 | |
Brian O'Connor | 7a71d5d | 2014-12-02 00:12:27 -0800 | [diff] [blame] | 89 | private static final EnumSet<IntentState> RECOMPILE |
| 90 | = EnumSet.of(INSTALL_REQ, FAILED, WITHDRAW_REQ); |
Brian O'Connor | 7a71d5d | 2014-12-02 00:12:27 -0800 | [diff] [blame] | 91 | |
Brian O'Connor | 66630c8 | 2014-10-02 21:08:19 -0700 | [diff] [blame] | 92 | // Collections for compiler, installer, and listener are ONOS instance local |
| 93 | private final ConcurrentMap<Class<? extends Intent>, |
| 94 | IntentCompiler<? extends Intent>> compilers = new ConcurrentHashMap<>(); |
Thomas Vachuska | b97cf28 | 2014-10-20 23:31:12 -0700 | [diff] [blame] | 95 | private final ConcurrentMap<Class<? extends Intent>, |
| 96 | IntentInstaller<? extends Intent>> installers = new ConcurrentHashMap<>(); |
Brian O'Connor | 66630c8 | 2014-10-02 21:08:19 -0700 | [diff] [blame] | 97 | |
| 98 | private final AbstractListenerRegistry<IntentEvent, IntentListener> |
tom | 95329eb | 2014-10-06 08:40:06 -0700 | [diff] [blame] | 99 | listenerRegistry = new AbstractListenerRegistry<>(); |
Brian O'Connor | 66630c8 | 2014-10-02 21:08:19 -0700 | [diff] [blame] | 100 | |
Brian O'Connor | 520c052 | 2014-11-23 23:50:47 -0800 | [diff] [blame] | 101 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
| 102 | protected CoreService coreService; |
Brian O'Connor | 66630c8 | 2014-10-02 21:08:19 -0700 | [diff] [blame] | 103 | |
| 104 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
| 105 | protected IntentStore store; |
| 106 | |
| 107 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
tom | 85258ee | 2014-10-07 00:10:02 -0700 | [diff] [blame] | 108 | protected ObjectiveTrackerService trackerService; |
tom | 95329eb | 2014-10-06 08:40:06 -0700 | [diff] [blame] | 109 | |
| 110 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
Brian O'Connor | 66630c8 | 2014-10-02 21:08:19 -0700 | [diff] [blame] | 111 | protected EventDeliveryService eventDispatcher; |
| 112 | |
Brian O'Connor | f2dbde5 | 2014-10-10 16:20:24 -0700 | [diff] [blame] | 113 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
| 114 | protected FlowRuleService flowRuleService; |
| 115 | |
Brian O'Connor | 520c052 | 2014-11-23 23:50:47 -0800 | [diff] [blame] | 116 | |
Brian O'Connor | db15b04 | 2015-02-04 14:59:28 -0800 | [diff] [blame] | 117 | private ExecutorService batchExecutor; |
| 118 | private ExecutorService workerExecutor; |
Brian O'Connor | 520c052 | 2014-11-23 23:50:47 -0800 | [diff] [blame] | 119 | |
| 120 | private final IntentStoreDelegate delegate = new InternalStoreDelegate(); |
| 121 | private final TopologyChangeDelegate topoDelegate = new InternalTopoChangeDelegate(); |
| 122 | private final IntentBatchDelegate batchDelegate = new InternalBatchDelegate(); |
| 123 | private IdGenerator idGenerator; |
| 124 | |
Brian O'Connor | b499b35 | 2015-02-03 16:46:15 -0800 | [diff] [blame] | 125 | private final IntentAccumulator accumulator = new IntentAccumulator(batchDelegate); |
Brian O'Connor | cff0332 | 2015-02-03 15:28:59 -0800 | [diff] [blame] | 126 | |
Brian O'Connor | 66630c8 | 2014-10-02 21:08:19 -0700 | [diff] [blame] | 127 | @Activate |
| 128 | public void activate() { |
| 129 | store.setDelegate(delegate); |
tom | 95329eb | 2014-10-06 08:40:06 -0700 | [diff] [blame] | 130 | trackerService.setDelegate(topoDelegate); |
Brian O'Connor | 66630c8 | 2014-10-02 21:08:19 -0700 | [diff] [blame] | 131 | eventDispatcher.addSink(IntentEvent.class, listenerRegistry); |
Brian O'Connor | db15b04 | 2015-02-04 14:59:28 -0800 | [diff] [blame] | 132 | batchExecutor = newSingleThreadExecutor(namedThreads("onos-intent-batch")); |
| 133 | workerExecutor = newFixedThreadPool(NUM_THREADS, namedThreads("onos-intent-worker-%d")); |
Brian O'Connor | 520c052 | 2014-11-23 23:50:47 -0800 | [diff] [blame] | 134 | idGenerator = coreService.getIdGenerator("intent-ids"); |
| 135 | Intent.bindIdGenerator(idGenerator); |
Brian O'Connor | 66630c8 | 2014-10-02 21:08:19 -0700 | [diff] [blame] | 136 | log.info("Started"); |
| 137 | } |
| 138 | |
| 139 | @Deactivate |
| 140 | public void deactivate() { |
| 141 | store.unsetDelegate(delegate); |
tom | 95329eb | 2014-10-06 08:40:06 -0700 | [diff] [blame] | 142 | trackerService.unsetDelegate(topoDelegate); |
Brian O'Connor | 66630c8 | 2014-10-02 21:08:19 -0700 | [diff] [blame] | 143 | eventDispatcher.removeSink(IntentEvent.class); |
Brian O'Connor | db15b04 | 2015-02-04 14:59:28 -0800 | [diff] [blame] | 144 | batchExecutor.shutdown(); |
Brian O'Connor | 520c052 | 2014-11-23 23:50:47 -0800 | [diff] [blame] | 145 | Intent.unbindIdGenerator(idGenerator); |
Brian O'Connor | 66630c8 | 2014-10-02 21:08:19 -0700 | [diff] [blame] | 146 | log.info("Stopped"); |
| 147 | } |
| 148 | |
| 149 | @Override |
| 150 | public void submit(Intent intent) { |
| 151 | checkNotNull(intent, INTENT_NULL); |
Brian O'Connor | cff0332 | 2015-02-03 15:28:59 -0800 | [diff] [blame] | 152 | IntentData data = new IntentData(intent, IntentState.INSTALL_REQ, null); |
Brian O'Connor | cff0332 | 2015-02-03 15:28:59 -0800 | [diff] [blame] | 153 | store.addPending(data); |
Brian O'Connor | 66630c8 | 2014-10-02 21:08:19 -0700 | [diff] [blame] | 154 | } |
| 155 | |
| 156 | @Override |
| 157 | public void withdraw(Intent intent) { |
| 158 | checkNotNull(intent, INTENT_NULL); |
Brian O'Connor | cff0332 | 2015-02-03 15:28:59 -0800 | [diff] [blame] | 159 | IntentData data = new IntentData(intent, IntentState.WITHDRAW_REQ, null); |
Brian O'Connor | cff0332 | 2015-02-03 15:28:59 -0800 | [diff] [blame] | 160 | store.addPending(data); |
Brian O'Connor | 66630c8 | 2014-10-02 21:08:19 -0700 | [diff] [blame] | 161 | } |
| 162 | |
Brian O'Connor | 66630c8 | 2014-10-02 21:08:19 -0700 | [diff] [blame] | 163 | @Override |
Ray Milkey | f9af43c | 2015-02-09 16:45:48 -0800 | [diff] [blame] | 164 | public Intent getIntent(Key key) { |
| 165 | return store.getIntent(key); |
| 166 | } |
| 167 | |
| 168 | @Override |
Brian O'Connor | 66630c8 | 2014-10-02 21:08:19 -0700 | [diff] [blame] | 169 | public Iterable<Intent> getIntents() { |
| 170 | return store.getIntents(); |
| 171 | } |
| 172 | |
| 173 | @Override |
| 174 | public long getIntentCount() { |
| 175 | return store.getIntentCount(); |
| 176 | } |
| 177 | |
| 178 | @Override |
Ray Milkey | f9af43c | 2015-02-09 16:45:48 -0800 | [diff] [blame] | 179 | public IntentState getIntentState(Key intentKey) { |
| 180 | checkNotNull(intentKey, INTENT_ID_NULL); |
| 181 | return store.getIntentState(intentKey); |
Brian O'Connor | 66630c8 | 2014-10-02 21:08:19 -0700 | [diff] [blame] | 182 | } |
| 183 | |
| 184 | @Override |
Ray Milkey | f9af43c | 2015-02-09 16:45:48 -0800 | [diff] [blame] | 185 | public List<Intent> getInstallableIntents(Key intentKey) { |
| 186 | checkNotNull(intentKey, INTENT_ID_NULL); |
| 187 | return store.getInstallableIntents(intentKey); |
Thomas Vachuska | 10d4abc | 2014-10-21 12:47:26 -0700 | [diff] [blame] | 188 | } |
| 189 | |
| 190 | @Override |
Brian O'Connor | 66630c8 | 2014-10-02 21:08:19 -0700 | [diff] [blame] | 191 | public void addListener(IntentListener listener) { |
| 192 | listenerRegistry.addListener(listener); |
| 193 | } |
| 194 | |
| 195 | @Override |
| 196 | public void removeListener(IntentListener listener) { |
| 197 | listenerRegistry.removeListener(listener); |
| 198 | } |
| 199 | |
| 200 | @Override |
| 201 | public <T extends Intent> void registerCompiler(Class<T> cls, IntentCompiler<T> compiler) { |
| 202 | compilers.put(cls, compiler); |
| 203 | } |
| 204 | |
| 205 | @Override |
| 206 | public <T extends Intent> void unregisterCompiler(Class<T> cls) { |
| 207 | compilers.remove(cls); |
| 208 | } |
| 209 | |
| 210 | @Override |
| 211 | public Map<Class<? extends Intent>, IntentCompiler<? extends Intent>> getCompilers() { |
| 212 | return ImmutableMap.copyOf(compilers); |
| 213 | } |
| 214 | |
| 215 | @Override |
Thomas Vachuska | b97cf28 | 2014-10-20 23:31:12 -0700 | [diff] [blame] | 216 | public <T extends Intent> void registerInstaller(Class<T> cls, IntentInstaller<T> installer) { |
Brian O'Connor | 66630c8 | 2014-10-02 21:08:19 -0700 | [diff] [blame] | 217 | installers.put(cls, installer); |
| 218 | } |
| 219 | |
| 220 | @Override |
Thomas Vachuska | b97cf28 | 2014-10-20 23:31:12 -0700 | [diff] [blame] | 221 | public <T extends Intent> void unregisterInstaller(Class<T> cls) { |
Brian O'Connor | 66630c8 | 2014-10-02 21:08:19 -0700 | [diff] [blame] | 222 | installers.remove(cls); |
| 223 | } |
| 224 | |
| 225 | @Override |
Thomas Vachuska | b97cf28 | 2014-10-20 23:31:12 -0700 | [diff] [blame] | 226 | public Map<Class<? extends Intent>, IntentInstaller<? extends Intent>> getInstallers() { |
Brian O'Connor | 66630c8 | 2014-10-02 21:08:19 -0700 | [diff] [blame] | 227 | return ImmutableMap.copyOf(installers); |
| 228 | } |
| 229 | |
| 230 | /** |
Brian O'Connor | 66630c8 | 2014-10-02 21:08:19 -0700 | [diff] [blame] | 231 | * Returns the corresponding intent compiler to the specified intent. |
| 232 | * |
| 233 | * @param intent intent |
tom | 95329eb | 2014-10-06 08:40:06 -0700 | [diff] [blame] | 234 | * @param <T> the type of intent |
Brian O'Connor | 66630c8 | 2014-10-02 21:08:19 -0700 | [diff] [blame] | 235 | * @return intent compiler corresponding to the specified intent |
| 236 | */ |
| 237 | private <T extends Intent> IntentCompiler<T> getCompiler(T intent) { |
| 238 | @SuppressWarnings("unchecked") |
| 239 | IntentCompiler<T> compiler = (IntentCompiler<T>) compilers.get(intent.getClass()); |
| 240 | if (compiler == null) { |
| 241 | throw new IntentException("no compiler for class " + intent.getClass()); |
| 242 | } |
| 243 | return compiler; |
| 244 | } |
| 245 | |
| 246 | /** |
| 247 | * Returns the corresponding intent installer to the specified installable intent. |
tom | 95329eb | 2014-10-06 08:40:06 -0700 | [diff] [blame] | 248 | * |
Brian O'Connor | 66630c8 | 2014-10-02 21:08:19 -0700 | [diff] [blame] | 249 | * @param intent intent |
tom | 95329eb | 2014-10-06 08:40:06 -0700 | [diff] [blame] | 250 | * @param <T> the type of installable intent |
Brian O'Connor | 66630c8 | 2014-10-02 21:08:19 -0700 | [diff] [blame] | 251 | * @return intent installer corresponding to the specified installable intent |
| 252 | */ |
Thomas Vachuska | b97cf28 | 2014-10-20 23:31:12 -0700 | [diff] [blame] | 253 | private <T extends Intent> IntentInstaller<T> getInstaller(T intent) { |
Brian O'Connor | 66630c8 | 2014-10-02 21:08:19 -0700 | [diff] [blame] | 254 | @SuppressWarnings("unchecked") |
| 255 | IntentInstaller<T> installer = (IntentInstaller<T>) installers.get(intent.getClass()); |
| 256 | if (installer == null) { |
| 257 | throw new IntentException("no installer for class " + intent.getClass()); |
| 258 | } |
| 259 | return installer; |
| 260 | } |
| 261 | |
| 262 | /** |
Brian O'Connor | cb900f4 | 2014-10-07 21:55:33 -0700 | [diff] [blame] | 263 | * Compiles an intent recursively. |
| 264 | * |
| 265 | * @param intent intent |
Jonathan Hart | d0ba217 | 2015-02-11 13:54:33 -0800 | [diff] [blame] | 266 | * @param previousInstallables previous intent installables |
Brian O'Connor | cb900f4 | 2014-10-07 21:55:33 -0700 | [diff] [blame] | 267 | * @return result of compilation |
| 268 | */ |
Sho SHIMIZU | 5cb438e | 2015-02-04 13:46:00 -0800 | [diff] [blame] | 269 | List<Intent> compileIntent(Intent intent, List<Intent> previousInstallables) { |
Thomas Vachuska | 4926c1b | 2014-10-21 00:44:10 -0700 | [diff] [blame] | 270 | if (intent.isInstallable()) { |
| 271 | return ImmutableList.of(intent); |
Brian O'Connor | 66630c8 | 2014-10-02 21:08:19 -0700 | [diff] [blame] | 272 | } |
Brian O'Connor | cb900f4 | 2014-10-07 21:55:33 -0700 | [diff] [blame] | 273 | |
Brian O'Connor | fa81eae | 2014-10-30 13:20:05 -0700 | [diff] [blame] | 274 | registerSubclassCompilerIfNeeded(intent); |
Brian O'Connor | fa81eae | 2014-10-30 13:20:05 -0700 | [diff] [blame] | 275 | // FIXME: get previous resources |
Thomas Vachuska | b97cf28 | 2014-10-20 23:31:12 -0700 | [diff] [blame] | 276 | List<Intent> installable = new ArrayList<>(); |
Sho SHIMIZU | adf8c48 | 2014-12-12 18:23:29 -0800 | [diff] [blame] | 277 | for (Intent compiled : getCompiler(intent).compile(intent, previousInstallables, null)) { |
| 278 | installable.addAll(compileIntent(compiled, previousInstallables)); |
Brian O'Connor | cb900f4 | 2014-10-07 21:55:33 -0700 | [diff] [blame] | 279 | } |
tom | 85258ee | 2014-10-07 00:10:02 -0700 | [diff] [blame] | 280 | return installable; |
Brian O'Connor | 66630c8 | 2014-10-02 21:08:19 -0700 | [diff] [blame] | 281 | } |
| 282 | |
Brian O'Connor | 0e271dc | 2015-02-04 18:20:25 -0800 | [diff] [blame] | 283 | //TODO javadoc |
| 284 | //FIXME |
Brian O'Connor | 7775bda | 2015-02-06 15:01:18 -0800 | [diff] [blame] | 285 | FlowRuleOperations coordinate(IntentData pending) { |
| 286 | List<Intent> installables = pending.installables(); |
| 287 | List<List<FlowRuleBatchOperation>> plans = new ArrayList<>(installables.size()); |
Brian O'Connor | 0e271dc | 2015-02-04 18:20:25 -0800 | [diff] [blame] | 288 | for (Intent installable : installables) { |
Sho SHIMIZU | b5cd581 | 2015-02-09 14:25:13 -0800 | [diff] [blame] | 289 | registerSubclassInstallerIfNeeded(installable); |
Brian O'Connor | ea2ba3e | 2015-02-12 11:27:55 -0800 | [diff] [blame] | 290 | //TODO consider migrating installers to FlowRuleOperations |
Sho SHIMIZU | b5cd581 | 2015-02-09 14:25:13 -0800 | [diff] [blame] | 291 | plans.add(getInstaller(installable).install(installable)); |
Brian O'Connor | 0e271dc | 2015-02-04 18:20:25 -0800 | [diff] [blame] | 292 | } |
Brian O'Connor | 7775bda | 2015-02-06 15:01:18 -0800 | [diff] [blame] | 293 | |
Brian O'Connor | ea2ba3e | 2015-02-12 11:27:55 -0800 | [diff] [blame] | 294 | return merge(plans).build(new FlowRuleOperationsContext() { // TODO move this out |
Brian O'Connor | 7775bda | 2015-02-06 15:01:18 -0800 | [diff] [blame] | 295 | @Override |
| 296 | public void onSuccess(FlowRuleOperations ops) { |
| 297 | log.info("Completed installing: {}", pending.key()); |
| 298 | pending.setState(INSTALLED); |
| 299 | store.write(pending); |
| 300 | } |
| 301 | |
| 302 | @Override |
| 303 | public void onError(FlowRuleOperations ops) { |
Brian O'Connor | ba1abbe | 2015-02-06 15:21:48 -0800 | [diff] [blame] | 304 | log.warn("Failed installation: {} {} on {}", pending.key(), |
| 305 | pending.intent(), ops); |
Brian O'Connor | ea2ba3e | 2015-02-12 11:27:55 -0800 | [diff] [blame] | 306 | //TODO store.write(pending.setState(BROKEN)); |
Ray Milkey | 9f74c08 | 2015-02-11 15:40:16 -0800 | [diff] [blame] | 307 | pending.setState(FAILED); |
| 308 | store.write(pending); |
Brian O'Connor | 7775bda | 2015-02-06 15:01:18 -0800 | [diff] [blame] | 309 | } |
| 310 | }); |
| 311 | } |
| 312 | |
Sho SHIMIZU | 37a24a8 | 2015-02-09 09:12:21 -0800 | [diff] [blame] | 313 | /** |
| 314 | * Generate a {@link FlowRuleOperations} instance from the specified intent data. |
| 315 | * |
| 316 | * @param current intent data stored in the store |
| 317 | * @return flow rule operations |
| 318 | */ |
Ray Milkey | 9f74c08 | 2015-02-11 15:40:16 -0800 | [diff] [blame] | 319 | FlowRuleOperations uninstallCoordinate(IntentData current, IntentData pending) { |
Sho SHIMIZU | 37a24a8 | 2015-02-09 09:12:21 -0800 | [diff] [blame] | 320 | List<Intent> installables = current.installables(); |
| 321 | List<List<FlowRuleBatchOperation>> plans = new ArrayList<>(); |
| 322 | for (Intent installable : installables) { |
Sho SHIMIZU | b5cd581 | 2015-02-09 14:25:13 -0800 | [diff] [blame] | 323 | plans.add(getInstaller(installable).uninstall(installable)); |
Sho SHIMIZU | 37a24a8 | 2015-02-09 09:12:21 -0800 | [diff] [blame] | 324 | } |
| 325 | |
| 326 | return merge(plans).build(new FlowRuleOperationsContext() { |
| 327 | @Override |
| 328 | public void onSuccess(FlowRuleOperations ops) { |
Ray Milkey | 9f74c08 | 2015-02-11 15:40:16 -0800 | [diff] [blame] | 329 | log.info("Completed withdrawing: {}", pending.key()); |
| 330 | pending.setState(WITHDRAWN); |
| 331 | pending.setInstallables(Collections.emptyList()); |
| 332 | store.write(pending); |
Sho SHIMIZU | 37a24a8 | 2015-02-09 09:12:21 -0800 | [diff] [blame] | 333 | } |
| 334 | |
| 335 | @Override |
| 336 | public void onError(FlowRuleOperations ops) { |
Ray Milkey | 9f74c08 | 2015-02-11 15:40:16 -0800 | [diff] [blame] | 337 | log.warn("Failed withdraw: {}", pending.key()); |
| 338 | pending.setState(FAILED); |
| 339 | store.write(pending); |
Sho SHIMIZU | 37a24a8 | 2015-02-09 09:12:21 -0800 | [diff] [blame] | 340 | } |
| 341 | }); |
| 342 | } |
| 343 | |
| 344 | |
Brian O'Connor | ea2ba3e | 2015-02-12 11:27:55 -0800 | [diff] [blame] | 345 | // TODO needs tests... or maybe it's just perfect |
Brian O'Connor | 7775bda | 2015-02-06 15:01:18 -0800 | [diff] [blame] | 346 | private FlowRuleOperations.Builder merge(List<List<FlowRuleBatchOperation>> plans) { |
| 347 | FlowRuleOperations.Builder builder = FlowRuleOperations.builder(); |
| 348 | // Build a batch one stage at a time |
| 349 | for (int stageNumber = 0;; stageNumber++) { |
| 350 | // Get the sub-stage from each plan (List<FlowRuleBatchOperation>) |
| 351 | for (Iterator<List<FlowRuleBatchOperation>> itr = plans.iterator(); itr.hasNext();) { |
| 352 | List<FlowRuleBatchOperation> plan = itr.next(); |
| 353 | if (plan.size() <= stageNumber) { |
| 354 | // we have consumed all stages from this plan, so remove it |
| 355 | itr.remove(); |
| 356 | continue; |
| 357 | } |
| 358 | // write operations from this sub-stage into the builder |
| 359 | FlowRuleBatchOperation stage = plan.get(stageNumber); |
| 360 | for (FlowRuleBatchEntry entry : stage.getOperations()) { |
| 361 | FlowRule rule = entry.target(); |
| 362 | switch (entry.operator()) { |
| 363 | case ADD: |
| 364 | builder.add(rule); |
| 365 | break; |
| 366 | case REMOVE: |
| 367 | builder.remove(rule); |
| 368 | break; |
| 369 | case MODIFY: |
| 370 | builder.modify(rule); |
| 371 | break; |
| 372 | default: |
| 373 | break; |
| 374 | } |
| 375 | } |
| 376 | } |
| 377 | // we are done with the stage, start the next one... |
| 378 | if (plans.isEmpty()) { |
| 379 | break; // we don't need to start a new stage, we are done. |
| 380 | } |
| 381 | builder.newStage(); |
| 382 | } |
| 383 | return builder; |
Brian O'Connor | 0e271dc | 2015-02-04 18:20:25 -0800 | [diff] [blame] | 384 | } |
| 385 | |
Brian O'Connor | 66630c8 | 2014-10-02 21:08:19 -0700 | [diff] [blame] | 386 | /** |
Brian O'Connor | 66630c8 | 2014-10-02 21:08:19 -0700 | [diff] [blame] | 387 | * Registers an intent compiler of the specified intent if an intent compiler |
| 388 | * for the intent is not registered. This method traverses the class hierarchy of |
| 389 | * the intent. Once an intent compiler for a parent type is found, this method |
| 390 | * registers the found intent compiler. |
| 391 | * |
| 392 | * @param intent intent |
| 393 | */ |
| 394 | private void registerSubclassCompilerIfNeeded(Intent intent) { |
| 395 | if (!compilers.containsKey(intent.getClass())) { |
| 396 | Class<?> cls = intent.getClass(); |
| 397 | while (cls != Object.class) { |
| 398 | // As long as we're within the Intent class descendants |
| 399 | if (Intent.class.isAssignableFrom(cls)) { |
| 400 | IntentCompiler<?> compiler = compilers.get(cls); |
| 401 | if (compiler != null) { |
| 402 | compilers.put(intent.getClass(), compiler); |
| 403 | return; |
| 404 | } |
| 405 | } |
| 406 | cls = cls.getSuperclass(); |
| 407 | } |
| 408 | } |
| 409 | } |
| 410 | |
| 411 | /** |
| 412 | * Registers an intent installer of the specified intent if an intent installer |
| 413 | * for the intent is not registered. This method traverses the class hierarchy of |
| 414 | * the intent. Once an intent installer for a parent type is found, this method |
| 415 | * registers the found intent installer. |
| 416 | * |
| 417 | * @param intent intent |
| 418 | */ |
Thomas Vachuska | b97cf28 | 2014-10-20 23:31:12 -0700 | [diff] [blame] | 419 | private void registerSubclassInstallerIfNeeded(Intent intent) { |
Brian O'Connor | 66630c8 | 2014-10-02 21:08:19 -0700 | [diff] [blame] | 420 | if (!installers.containsKey(intent.getClass())) { |
| 421 | Class<?> cls = intent.getClass(); |
| 422 | while (cls != Object.class) { |
Thomas Vachuska | b97cf28 | 2014-10-20 23:31:12 -0700 | [diff] [blame] | 423 | // As long as we're within the Intent class descendants |
| 424 | if (Intent.class.isAssignableFrom(cls)) { |
Brian O'Connor | 66630c8 | 2014-10-02 21:08:19 -0700 | [diff] [blame] | 425 | IntentInstaller<?> installer = installers.get(cls); |
| 426 | if (installer != null) { |
| 427 | installers.put(intent.getClass(), installer); |
| 428 | return; |
| 429 | } |
| 430 | } |
| 431 | cls = cls.getSuperclass(); |
| 432 | } |
| 433 | } |
| 434 | } |
| 435 | |
Brian O'Connor | 66630c8 | 2014-10-02 21:08:19 -0700 | [diff] [blame] | 436 | // Store delegate to re-post events emitted from the store. |
| 437 | private class InternalStoreDelegate implements IntentStoreDelegate { |
| 438 | @Override |
| 439 | public void notify(IntentEvent event) { |
tom | 85258ee | 2014-10-07 00:10:02 -0700 | [diff] [blame] | 440 | eventDispatcher.post(event); |
Brian O'Connor | 66630c8 | 2014-10-02 21:08:19 -0700 | [diff] [blame] | 441 | } |
Brian O'Connor | ea4d7d1 | 2015-01-28 16:37:46 -0800 | [diff] [blame] | 442 | |
| 443 | @Override |
Brian O'Connor | cff0332 | 2015-02-03 15:28:59 -0800 | [diff] [blame] | 444 | public void process(IntentData data) { |
| 445 | accumulator.add(data); |
Brian O'Connor | ea4d7d1 | 2015-01-28 16:37:46 -0800 | [diff] [blame] | 446 | } |
Brian O'Connor | 66630c8 | 2014-10-02 21:08:19 -0700 | [diff] [blame] | 447 | } |
| 448 | |
Ray Milkey | f9af43c | 2015-02-09 16:45:48 -0800 | [diff] [blame] | 449 | private void buildAndSubmitBatches(Iterable<Key> intentKeys, |
Brian O'Connor | 72a034c | 2014-11-26 18:24:23 -0800 | [diff] [blame] | 450 | boolean compileAllFailed) { |
Brian O'Connor | 72a034c | 2014-11-26 18:24:23 -0800 | [diff] [blame] | 451 | // Attempt recompilation of the specified intents first. |
Ray Milkey | f9af43c | 2015-02-09 16:45:48 -0800 | [diff] [blame] | 452 | for (Key key : intentKeys) { |
| 453 | Intent intent = store.getIntent(key); |
Brian O'Connor | 72a034c | 2014-11-26 18:24:23 -0800 | [diff] [blame] | 454 | if (intent == null) { |
| 455 | continue; |
| 456 | } |
Brian O'Connor | 03406a4 | 2015-02-03 17:28:57 -0800 | [diff] [blame] | 457 | submit(intent); |
Brian O'Connor | 72a034c | 2014-11-26 18:24:23 -0800 | [diff] [blame] | 458 | } |
| 459 | |
| 460 | if (compileAllFailed) { |
| 461 | // If required, compile all currently failed intents. |
| 462 | for (Intent intent : getIntents()) { |
Ray Milkey | f9af43c | 2015-02-09 16:45:48 -0800 | [diff] [blame] | 463 | IntentState state = getIntentState(intent.key()); |
Brian O'Connor | 7a71d5d | 2014-12-02 00:12:27 -0800 | [diff] [blame] | 464 | if (RECOMPILE.contains(state)) { |
Brian O'Connor | 7a71d5d | 2014-12-02 00:12:27 -0800 | [diff] [blame] | 465 | if (state == WITHDRAW_REQ) { |
Brian O'Connor | 03406a4 | 2015-02-03 17:28:57 -0800 | [diff] [blame] | 466 | withdraw(intent); |
Brian O'Connor | 7a71d5d | 2014-12-02 00:12:27 -0800 | [diff] [blame] | 467 | } else { |
Brian O'Connor | 03406a4 | 2015-02-03 17:28:57 -0800 | [diff] [blame] | 468 | submit(intent); |
Brian O'Connor | 7a71d5d | 2014-12-02 00:12:27 -0800 | [diff] [blame] | 469 | } |
Brian O'Connor | 72a034c | 2014-11-26 18:24:23 -0800 | [diff] [blame] | 470 | } |
| 471 | } |
| 472 | } |
| 473 | |
Brian O'Connor | b499b35 | 2015-02-03 16:46:15 -0800 | [diff] [blame] | 474 | //FIXME |
| 475 | // for (ApplicationId appId : batches.keySet()) { |
| 476 | // if (batchService.isLocalLeader(appId)) { |
| 477 | // execute(batches.get(appId).build()); |
| 478 | // } |
| 479 | // } |
Brian O'Connor | 72a034c | 2014-11-26 18:24:23 -0800 | [diff] [blame] | 480 | } |
| 481 | |
tom | 95329eb | 2014-10-06 08:40:06 -0700 | [diff] [blame] | 482 | // Topology change delegate |
| 483 | private class InternalTopoChangeDelegate implements TopologyChangeDelegate { |
| 484 | @Override |
Ray Milkey | f9af43c | 2015-02-09 16:45:48 -0800 | [diff] [blame] | 485 | public void triggerCompile(Iterable<Key> intentKeys, |
tom | 85258ee | 2014-10-07 00:10:02 -0700 | [diff] [blame] | 486 | boolean compileAllFailed) { |
Ray Milkey | f9af43c | 2015-02-09 16:45:48 -0800 | [diff] [blame] | 487 | buildAndSubmitBatches(intentKeys, compileAllFailed); |
tom | 95329eb | 2014-10-06 08:40:06 -0700 | [diff] [blame] | 488 | } |
tom | 95329eb | 2014-10-06 08:40:06 -0700 | [diff] [blame] | 489 | } |
tom | 85258ee | 2014-10-07 00:10:02 -0700 | [diff] [blame] | 490 | |
Brian O'Connor | b499b35 | 2015-02-03 16:46:15 -0800 | [diff] [blame] | 491 | private IntentUpdate createIntentUpdate(IntentData intentData) { |
Brian O'Connor | b499b35 | 2015-02-03 16:46:15 -0800 | [diff] [blame] | 492 | switch (intentData.state()) { |
| 493 | case INSTALL_REQ: |
Brian O'Connor | 0e271dc | 2015-02-04 18:20:25 -0800 | [diff] [blame] | 494 | return new InstallRequest(this, intentData); |
Brian O'Connor | b499b35 | 2015-02-03 16:46:15 -0800 | [diff] [blame] | 495 | case WITHDRAW_REQ: |
Brian O'Connor | 0e271dc | 2015-02-04 18:20:25 -0800 | [diff] [blame] | 496 | return new WithdrawRequest(this, intentData); |
Brian O'Connor | b499b35 | 2015-02-03 16:46:15 -0800 | [diff] [blame] | 497 | // fallthrough |
| 498 | case COMPILING: |
| 499 | case INSTALLING: |
| 500 | case INSTALLED: |
| 501 | case RECOMPILING: |
| 502 | case WITHDRAWING: |
| 503 | case WITHDRAWN: |
| 504 | case FAILED: |
Sho SHIMIZU | adf8c48 | 2014-12-12 18:23:29 -0800 | [diff] [blame] | 505 | default: |
| 506 | // illegal state |
Brian O'Connor | 0e271dc | 2015-02-04 18:20:25 -0800 | [diff] [blame] | 507 | return new CompilingFailed(intentData); |
Brian O'Connor | fa81eae | 2014-10-30 13:20:05 -0700 | [diff] [blame] | 508 | } |
Brian O'Connor | fa81eae | 2014-10-30 13:20:05 -0700 | [diff] [blame] | 509 | } |
| 510 | |
Brian O'Connor | 0e271dc | 2015-02-04 18:20:25 -0800 | [diff] [blame] | 511 | private Future<CompletedIntentUpdate> submitIntentData(IntentData data) { |
| 512 | return workerExecutor.submit(new IntentWorker(data)); |
Sho SHIMIZU | 8d9d136 | 2015-02-04 12:28:15 -0800 | [diff] [blame] | 513 | } |
| 514 | |
Sho SHIMIZU | adf8c48 | 2014-12-12 18:23:29 -0800 | [diff] [blame] | 515 | private class IntentBatchPreprocess implements Runnable { |
| 516 | |
| 517 | // TODO make this configurable |
| 518 | private static final int TIMEOUT_PER_OP = 500; // ms |
| 519 | protected static final int MAX_ATTEMPTS = 3; |
| 520 | |
Sho SHIMIZU | 5f281a4 | 2015-02-04 15:29:11 -0800 | [diff] [blame] | 521 | protected final Collection<IntentData> data; |
Sho SHIMIZU | adf8c48 | 2014-12-12 18:23:29 -0800 | [diff] [blame] | 522 | |
| 523 | // future holding current FlowRuleBatch installation result |
| 524 | protected final long startTime = System.currentTimeMillis(); |
| 525 | protected final long endTime; |
| 526 | |
Sho SHIMIZU | 5f281a4 | 2015-02-04 15:29:11 -0800 | [diff] [blame] | 527 | private IntentBatchPreprocess(Collection<IntentData> data, long endTime) { |
| 528 | this.data = checkNotNull(data); |
Sho SHIMIZU | adf8c48 | 2014-12-12 18:23:29 -0800 | [diff] [blame] | 529 | this.endTime = endTime; |
| 530 | } |
| 531 | |
Sho SHIMIZU | 5f281a4 | 2015-02-04 15:29:11 -0800 | [diff] [blame] | 532 | public IntentBatchPreprocess(Collection<IntentData> data) { |
| 533 | this(data, System.currentTimeMillis() + data.size() * TIMEOUT_PER_OP); |
Sho SHIMIZU | adf8c48 | 2014-12-12 18:23:29 -0800 | [diff] [blame] | 534 | } |
| 535 | |
| 536 | // FIXME compute reasonable timeouts |
| 537 | protected long calculateTimeoutLimit() { |
Sho SHIMIZU | 5f281a4 | 2015-02-04 15:29:11 -0800 | [diff] [blame] | 538 | return System.currentTimeMillis() + data.size() * TIMEOUT_PER_OP; |
Sho SHIMIZU | adf8c48 | 2014-12-12 18:23:29 -0800 | [diff] [blame] | 539 | } |
| 540 | |
| 541 | @Override |
| 542 | public void run() { |
| 543 | try { |
Brian O'Connor | 0e271dc | 2015-02-04 18:20:25 -0800 | [diff] [blame] | 544 | /* |
| 545 | 1. wrap each intentdata in a runnable and submit |
| 546 | 2. wait for completion of all the work |
| 547 | 3. accumulate results and submit batch write of IntentData to store |
| 548 | (we can also try to update these individually) |
| 549 | */ |
| 550 | submitUpdates(waitForFutures(createIntentUpdates())); |
Sho SHIMIZU | adf8c48 | 2014-12-12 18:23:29 -0800 | [diff] [blame] | 551 | } catch (Exception e) { |
| 552 | log.error("Error submitting batches:", e); |
| 553 | // FIXME incomplete Intents should be cleaned up |
| 554 | // (transition to FAILED, etc.) |
| 555 | |
Sho SHIMIZU | adf8c48 | 2014-12-12 18:23:29 -0800 | [diff] [blame] | 556 | // the batch has failed |
| 557 | // TODO: maybe we should do more? |
| 558 | log.error("Walk the plank, matey..."); |
Brian O'Connor | b499b35 | 2015-02-03 16:46:15 -0800 | [diff] [blame] | 559 | //FIXME |
Sho SHIMIZU | 5f281a4 | 2015-02-04 15:29:11 -0800 | [diff] [blame] | 560 | // batchService.removeIntentOperations(data); |
Sho SHIMIZU | adf8c48 | 2014-12-12 18:23:29 -0800 | [diff] [blame] | 561 | } |
| 562 | } |
| 563 | |
Brian O'Connor | 0e271dc | 2015-02-04 18:20:25 -0800 | [diff] [blame] | 564 | private List<Future<CompletedIntentUpdate>> createIntentUpdates() { |
Sho SHIMIZU | 5f281a4 | 2015-02-04 15:29:11 -0800 | [diff] [blame] | 565 | return data.stream() |
Brian O'Connor | 0e271dc | 2015-02-04 18:20:25 -0800 | [diff] [blame] | 566 | .map(IntentManager.this::submitIntentData) |
| 567 | .collect(Collectors.toList()); |
| 568 | } |
| 569 | |
| 570 | private List<CompletedIntentUpdate> waitForFutures(List<Future<CompletedIntentUpdate>> futures) { |
| 571 | ImmutableList.Builder<CompletedIntentUpdate> updateBuilder = ImmutableList.builder(); |
| 572 | for (Future<CompletedIntentUpdate> future : futures) { |
| 573 | try { |
| 574 | updateBuilder.add(future.get()); |
| 575 | } catch (InterruptedException | ExecutionException e) { |
| 576 | //FIXME |
| 577 | log.warn("Future failed: {}", e); |
| 578 | } |
| 579 | } |
| 580 | return updateBuilder.build(); |
| 581 | } |
| 582 | |
| 583 | private void submitUpdates(List<CompletedIntentUpdate> updates) { |
| 584 | store.batchWrite(updates.stream() |
| 585 | .map(CompletedIntentUpdate::data) |
| 586 | .collect(Collectors.toList())); |
Sho SHIMIZU | adf8c48 | 2014-12-12 18:23:29 -0800 | [diff] [blame] | 587 | } |
Sho SHIMIZU | adf8c48 | 2014-12-12 18:23:29 -0800 | [diff] [blame] | 588 | } |
Yuta HIGUCHI | c2bf3d8 | 2014-11-28 18:50:41 -0800 | [diff] [blame] | 589 | |
Brian O'Connor | 0e271dc | 2015-02-04 18:20:25 -0800 | [diff] [blame] | 590 | private final class IntentWorker implements Callable<CompletedIntentUpdate> { |
Brian O'Connor | db15b04 | 2015-02-04 14:59:28 -0800 | [diff] [blame] | 591 | |
| 592 | private final IntentData data; |
| 593 | |
| 594 | private IntentWorker(IntentData data) { |
| 595 | this.data = data; |
| 596 | } |
| 597 | |
| 598 | @Override |
Brian O'Connor | 0e271dc | 2015-02-04 18:20:25 -0800 | [diff] [blame] | 599 | public CompletedIntentUpdate call() throws Exception { |
Brian O'Connor | db15b04 | 2015-02-04 14:59:28 -0800 | [diff] [blame] | 600 | IntentUpdate update = createIntentUpdate(data); |
| 601 | Optional<IntentUpdate> currentPhase = Optional.of(update); |
| 602 | IntentUpdate previousPhase = update; |
| 603 | |
| 604 | while (currentPhase.isPresent()) { |
| 605 | previousPhase = currentPhase.get(); |
| 606 | currentPhase = previousPhase.execute(); |
| 607 | } |
Brian O'Connor | 0e271dc | 2015-02-04 18:20:25 -0800 | [diff] [blame] | 608 | return (CompletedIntentUpdate) previousPhase; |
Brian O'Connor | 427a176 | 2014-11-19 18:40:32 -0800 | [diff] [blame] | 609 | } |
Brian O'Connor | cb900f4 | 2014-10-07 21:55:33 -0700 | [diff] [blame] | 610 | } |
Brian O'Connor | fa81eae | 2014-10-30 13:20:05 -0700 | [diff] [blame] | 611 | |
| 612 | private class InternalBatchDelegate implements IntentBatchDelegate { |
| 613 | @Override |
Brian O'Connor | b499b35 | 2015-02-03 16:46:15 -0800 | [diff] [blame] | 614 | public void execute(Collection<IntentData> operations) { |
| 615 | log.info("Execute {} operation(s).", operations.size()); |
| 616 | log.debug("Execute operations: {}", operations); |
Brian O'Connor | db15b04 | 2015-02-04 14:59:28 -0800 | [diff] [blame] | 617 | batchExecutor.execute(new IntentBatchPreprocess(operations)); |
| 618 | // TODO ensure that only one batch is in flight at a time |
Brian O'Connor | fa81eae | 2014-10-30 13:20:05 -0700 | [diff] [blame] | 619 | } |
Brian O'Connor | fa81eae | 2014-10-30 13:20:05 -0700 | [diff] [blame] | 620 | } |
Brian O'Connor | 66630c8 | 2014-10-02 21:08:19 -0700 | [diff] [blame] | 621 | } |