Brian O'Connor | 3c58e96 | 2015-04-28 23:21:51 -0700 | [diff] [blame] | 1 | /* |
Brian O'Connor | a09fe5b | 2017-08-03 21:12:30 -0700 | [diff] [blame] | 2 | * Copyright 2015-present Open Networking Foundation |
Brian O'Connor | 3c58e96 | 2015-04-28 23:21:51 -0700 | [diff] [blame] | 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 | */ |
| 16 | package org.onosproject.net.intent.impl; |
| 17 | |
Brian O'Connor | 3c58e96 | 2015-04-28 23:21:51 -0700 | [diff] [blame] | 18 | import org.onosproject.cfg.ComponentConfigService; |
| 19 | import org.onosproject.net.intent.IntentData; |
| 20 | import org.onosproject.net.intent.IntentEvent; |
| 21 | import org.onosproject.net.intent.IntentListener; |
| 22 | import org.onosproject.net.intent.IntentService; |
| 23 | import org.onosproject.net.intent.IntentStore; |
Brian O'Connor | a6c9b5c | 2015-04-29 22:38:29 -0700 | [diff] [blame] | 24 | import org.onosproject.net.intent.Key; |
Pier Luigi | e6caf68 | 2017-01-26 15:25:09 -0800 | [diff] [blame] | 25 | import org.onosproject.store.service.WallClockTimestamp; |
Brian O'Connor | 3c58e96 | 2015-04-28 23:21:51 -0700 | [diff] [blame] | 26 | import org.osgi.service.component.ComponentContext; |
Ray Milkey | d84f89b | 2018-08-17 14:54:17 -0700 | [diff] [blame] | 27 | import org.osgi.service.component.annotations.Activate; |
| 28 | import org.osgi.service.component.annotations.Component; |
| 29 | import org.osgi.service.component.annotations.Deactivate; |
| 30 | import org.osgi.service.component.annotations.Modified; |
| 31 | import org.osgi.service.component.annotations.Reference; |
| 32 | import org.osgi.service.component.annotations.ReferenceCardinality; |
Brian O'Connor | 3c58e96 | 2015-04-28 23:21:51 -0700 | [diff] [blame] | 33 | import org.slf4j.Logger; |
| 34 | |
| 35 | import java.util.Dictionary; |
| 36 | import java.util.Properties; |
| 37 | import java.util.Timer; |
| 38 | import java.util.TimerTask; |
| 39 | import java.util.concurrent.ExecutorService; |
| 40 | |
| 41 | import static com.google.common.base.Strings.isNullOrEmpty; |
| 42 | import static java.util.concurrent.Executors.newSingleThreadExecutor; |
| 43 | import static org.onlab.util.Tools.get; |
| 44 | import static org.onlab.util.Tools.groupedThreads; |
Ray Milkey | d04e227 | 2018-10-16 18:20:18 -0700 | [diff] [blame] | 45 | import static org.onosproject.net.OsgiPropertyConstants.ICU_ENABLED; |
| 46 | import static org.onosproject.net.OsgiPropertyConstants.ICU_ENABLED_DEFAULT; |
| 47 | import static org.onosproject.net.OsgiPropertyConstants.ICU_PERIOD; |
| 48 | import static org.onosproject.net.OsgiPropertyConstants.ICU_PERIOD_DEFAULT; |
| 49 | import static org.onosproject.net.OsgiPropertyConstants.ICU_RETRY_THRESHOLD; |
| 50 | import static org.onosproject.net.OsgiPropertyConstants.ICU_RETRY_THRESHOLD_DEFAULT; |
Brian O'Connor | 3c58e96 | 2015-04-28 23:21:51 -0700 | [diff] [blame] | 51 | import static org.slf4j.LoggerFactory.getLogger; |
| 52 | |
| 53 | /** |
Brian O'Connor | a6c9b5c | 2015-04-29 22:38:29 -0700 | [diff] [blame] | 54 | * This component cleans up intents that have encountered errors or otherwise |
| 55 | * stalled during installation or withdrawal. |
| 56 | * <p> |
| 57 | * It periodically polls (based on configured period) for pending and CORRUPT |
| 58 | * intents from the store and retries. It also listens for CORRUPT event |
| 59 | * notifications, which signify errors in processing, and retries. |
| 60 | * </p> |
Brian O'Connor | 3c58e96 | 2015-04-28 23:21:51 -0700 | [diff] [blame] | 61 | */ |
Ray Milkey | d04e227 | 2018-10-16 18:20:18 -0700 | [diff] [blame] | 62 | @Component( |
| 63 | immediate = true, |
| 64 | property = { |
Ray Milkey | 2d7bca1 | 2018-10-17 14:51:52 -0700 | [diff] [blame] | 65 | ICU_ENABLED + ":Boolean=" + ICU_ENABLED_DEFAULT, |
| 66 | ICU_PERIOD + ":Integer=" + ICU_PERIOD_DEFAULT, |
| 67 | ICU_RETRY_THRESHOLD + ":Integer=" + ICU_RETRY_THRESHOLD_DEFAULT |
Ray Milkey | d04e227 | 2018-10-16 18:20:18 -0700 | [diff] [blame] | 68 | } |
| 69 | ) |
Brian O'Connor | 3c58e96 | 2015-04-28 23:21:51 -0700 | [diff] [blame] | 70 | public class IntentCleanup implements Runnable, IntentListener { |
| 71 | |
Brian O'Connor | cdec493 | 2015-04-30 16:16:47 -0700 | [diff] [blame] | 72 | private static final Logger log = getLogger(IntentCleanup.class); |
Brian O'Connor | 3c58e96 | 2015-04-28 23:21:51 -0700 | [diff] [blame] | 73 | |
Pier Luigi | e6caf68 | 2017-01-26 15:25:09 -0800 | [diff] [blame] | 74 | // Logical timeout for stuck Intents in INSTALLING or WITHDRAWING. The unit is seconds |
| 75 | private static final int INSTALLING_WITHDRAWING_PERIOD = 120; |
| 76 | |
Ray Milkey | d04e227 | 2018-10-16 18:20:18 -0700 | [diff] [blame] | 77 | |
| 78 | |
Brian O'Connor | 3c58e96 | 2015-04-28 23:21:51 -0700 | [diff] [blame] | 79 | |
Ray Milkey | d84f89b | 2018-08-17 14:54:17 -0700 | [diff] [blame] | 80 | //@Property(name = "enabled", boolValue = true, |
| 81 | // label = "Enables/disables the intent cleanup component") |
Ray Milkey | d04e227 | 2018-10-16 18:20:18 -0700 | [diff] [blame] | 82 | private boolean enabled = ICU_ENABLED_DEFAULT; |
Brian O'Connor | 5fcf6f5 | 2015-05-28 17:34:26 -0700 | [diff] [blame] | 83 | |
Ray Milkey | d84f89b | 2018-08-17 14:54:17 -0700 | [diff] [blame] | 84 | //@Property(name = "period", intValue = DEFAULT_PERIOD, |
| 85 | // label = "Frequency in ms between cleanup runs") |
Ray Milkey | d04e227 | 2018-10-16 18:20:18 -0700 | [diff] [blame] | 86 | protected int period = ICU_PERIOD_DEFAULT; |
Brian O'Connor | a6c9b5c | 2015-04-29 22:38:29 -0700 | [diff] [blame] | 87 | private long periodMs; |
Pier Luigi | e6caf68 | 2017-01-26 15:25:09 -0800 | [diff] [blame] | 88 | private long periodMsForStuck; |
Brian O'Connor | 3c58e96 | 2015-04-28 23:21:51 -0700 | [diff] [blame] | 89 | |
Ray Milkey | d84f89b | 2018-08-17 14:54:17 -0700 | [diff] [blame] | 90 | //@Property(name = "retryThreshold", intValue = DEFAULT_THRESHOLD, |
| 91 | // label = "Number of times to retry CORRUPT intent without delay") |
Ray Milkey | d04e227 | 2018-10-16 18:20:18 -0700 | [diff] [blame] | 92 | protected int retryThreshold = ICU_RETRY_THRESHOLD_DEFAULT; |
Brian O'Connor | 6d8e317 | 2015-04-30 15:43:57 -0700 | [diff] [blame] | 93 | |
Ray Milkey | d84f89b | 2018-08-17 14:54:17 -0700 | [diff] [blame] | 94 | @Reference(cardinality = ReferenceCardinality.MANDATORY) |
Brian O'Connor | 3c58e96 | 2015-04-28 23:21:51 -0700 | [diff] [blame] | 95 | protected IntentService service; |
| 96 | |
Ray Milkey | d84f89b | 2018-08-17 14:54:17 -0700 | [diff] [blame] | 97 | @Reference(cardinality = ReferenceCardinality.MANDATORY) |
Brian O'Connor | 3c58e96 | 2015-04-28 23:21:51 -0700 | [diff] [blame] | 98 | protected IntentStore store; |
| 99 | |
Ray Milkey | d84f89b | 2018-08-17 14:54:17 -0700 | [diff] [blame] | 100 | @Reference(cardinality = ReferenceCardinality.MANDATORY) |
Brian O'Connor | 3c58e96 | 2015-04-28 23:21:51 -0700 | [diff] [blame] | 101 | protected ComponentConfigService cfgService; |
| 102 | |
| 103 | private ExecutorService executor; |
| 104 | private Timer timer; |
| 105 | private TimerTask timerTask; |
| 106 | |
| 107 | @Activate |
| 108 | public void activate() { |
| 109 | cfgService.registerProperties(getClass()); |
HIGUCHI Yuta | d9e0105 | 2016-04-14 09:31:42 -0700 | [diff] [blame] | 110 | executor = newSingleThreadExecutor(groupedThreads("onos/intent", "cleanup", log)); |
Brian O'Connor | 3c58e96 | 2015-04-28 23:21:51 -0700 | [diff] [blame] | 111 | timer = new Timer("onos-intent-cleanup-timer"); |
| 112 | service.addListener(this); |
| 113 | adjustRate(); |
| 114 | log.info("Started"); |
| 115 | } |
| 116 | |
| 117 | @Deactivate |
| 118 | public void deactivate() { |
| 119 | cfgService.unregisterProperties(getClass(), false); |
| 120 | service.removeListener(this); |
| 121 | timer.cancel(); |
| 122 | timerTask = null; |
| 123 | executor.shutdown(); |
| 124 | log.info("Stopped"); |
| 125 | } |
| 126 | |
| 127 | @Modified |
| 128 | public void modified(ComponentContext context) { |
| 129 | Dictionary<?, ?> properties = context != null ? context.getProperties() : new Properties(); |
| 130 | |
| 131 | int newPeriod; |
Brian O'Connor | 5fcf6f5 | 2015-05-28 17:34:26 -0700 | [diff] [blame] | 132 | boolean newEnabled; |
Brian O'Connor | 3c58e96 | 2015-04-28 23:21:51 -0700 | [diff] [blame] | 133 | try { |
| 134 | String s = get(properties, "period"); |
| 135 | newPeriod = isNullOrEmpty(s) ? period : Integer.parseInt(s.trim()); |
Brian O'Connor | 6d8e317 | 2015-04-30 15:43:57 -0700 | [diff] [blame] | 136 | |
| 137 | s = get(properties, "retryThreshold"); |
Brian O'Connor | 5fcf6f5 | 2015-05-28 17:34:26 -0700 | [diff] [blame] | 138 | retryThreshold = isNullOrEmpty(s) ? retryThreshold : Integer.parseInt(s.trim()); |
| 139 | |
| 140 | s = get(properties, "enabled"); |
| 141 | newEnabled = isNullOrEmpty(s) ? enabled : Boolean.parseBoolean(s.trim()); |
Brian O'Connor | 3c58e96 | 2015-04-28 23:21:51 -0700 | [diff] [blame] | 142 | } catch (NumberFormatException e) { |
| 143 | log.warn(e.getMessage()); |
| 144 | newPeriod = period; |
Brian O'Connor | 5fcf6f5 | 2015-05-28 17:34:26 -0700 | [diff] [blame] | 145 | newEnabled = enabled; |
Brian O'Connor | 3c58e96 | 2015-04-28 23:21:51 -0700 | [diff] [blame] | 146 | } |
| 147 | |
| 148 | // Any change in the following parameters implies hard restart |
Pier Luigi | e6caf68 | 2017-01-26 15:25:09 -0800 | [diff] [blame] | 149 | // We could further restrict only for values multiple of the period |
| 150 | // of the stuck intents |
| 151 | if (newPeriod != period || enabled != newEnabled || newPeriod <= INSTALLING_WITHDRAWING_PERIOD) { |
Brian O'Connor | 3c58e96 | 2015-04-28 23:21:51 -0700 | [diff] [blame] | 152 | period = newPeriod; |
Brian O'Connor | 5fcf6f5 | 2015-05-28 17:34:26 -0700 | [diff] [blame] | 153 | enabled = newEnabled; |
Brian O'Connor | 3c58e96 | 2015-04-28 23:21:51 -0700 | [diff] [blame] | 154 | adjustRate(); |
| 155 | } |
| 156 | |
Brian O'Connor | 5fcf6f5 | 2015-05-28 17:34:26 -0700 | [diff] [blame] | 157 | log.info("Settings: enabled={}, period={}, retryThreshold={}", |
| 158 | enabled, period, retryThreshold); |
Brian O'Connor | 3c58e96 | 2015-04-28 23:21:51 -0700 | [diff] [blame] | 159 | } |
| 160 | |
Brian O'Connor | eba4e34 | 2015-04-30 22:50:13 -0700 | [diff] [blame] | 161 | protected void adjustRate() { |
Brian O'Connor | 3c58e96 | 2015-04-28 23:21:51 -0700 | [diff] [blame] | 162 | if (timerTask != null) { |
| 163 | timerTask.cancel(); |
Brian O'Connor | 5fcf6f5 | 2015-05-28 17:34:26 -0700 | [diff] [blame] | 164 | timerTask = null; |
Brian O'Connor | 3c58e96 | 2015-04-28 23:21:51 -0700 | [diff] [blame] | 165 | } |
| 166 | |
Brian O'Connor | 5fcf6f5 | 2015-05-28 17:34:26 -0700 | [diff] [blame] | 167 | if (enabled) { |
| 168 | timerTask = new TimerTask() { |
| 169 | @Override |
| 170 | public void run() { |
HIGUCHI Yuta | d9e0105 | 2016-04-14 09:31:42 -0700 | [diff] [blame] | 171 | executor.execute(IntentCleanup.this); |
Brian O'Connor | 5fcf6f5 | 2015-05-28 17:34:26 -0700 | [diff] [blame] | 172 | } |
| 173 | }; |
Pier Luigi | e6caf68 | 2017-01-26 15:25:09 -0800 | [diff] [blame] | 174 | // Convert to ms |
Ray Milkey | 3717e60 | 2018-02-01 13:49:47 -0800 | [diff] [blame] | 175 | periodMs = period * 1_000L; |
| 176 | periodMsForStuck = INSTALLING_WITHDRAWING_PERIOD * 1000L; |
Pier Luigi | e6caf68 | 2017-01-26 15:25:09 -0800 | [diff] [blame] | 177 | // Schedule the executions |
Brian O'Connor | 5fcf6f5 | 2015-05-28 17:34:26 -0700 | [diff] [blame] | 178 | timer.scheduleAtFixedRate(timerTask, periodMs, periodMs); |
| 179 | } |
Brian O'Connor | 3c58e96 | 2015-04-28 23:21:51 -0700 | [diff] [blame] | 180 | } |
| 181 | |
| 182 | |
| 183 | @Override |
| 184 | public void run() { |
| 185 | try { |
| 186 | cleanup(); |
| 187 | } catch (Exception e) { |
| 188 | log.warn("Caught exception during Intent cleanup", e); |
| 189 | } |
| 190 | } |
| 191 | |
Brian O'Connor | a6c9b5c | 2015-04-29 22:38:29 -0700 | [diff] [blame] | 192 | private void resubmitCorrupt(IntentData intentData, boolean checkThreshold) { |
Brian O'Connor | 6d8e317 | 2015-04-30 15:43:57 -0700 | [diff] [blame] | 193 | if (checkThreshold && intentData.errorCount() >= retryThreshold) { |
Brian O'Connor | 3822430 | 2016-08-02 22:03:01 -0700 | [diff] [blame] | 194 | //FIXME trace or debug statement? |
Brian O'Connor | 6d8e317 | 2015-04-30 15:43:57 -0700 | [diff] [blame] | 195 | return; // threshold met or exceeded |
Brian O'Connor | 3822430 | 2016-08-02 22:03:01 -0700 | [diff] [blame] | 196 | } // FIXME should we backoff here? |
Brian O'Connor | a6c9b5c | 2015-04-29 22:38:29 -0700 | [diff] [blame] | 197 | |
| 198 | switch (intentData.request()) { |
| 199 | case INSTALL_REQ: |
| 200 | service.submit(intentData.intent()); |
| 201 | break; |
| 202 | case WITHDRAW_REQ: |
| 203 | service.withdraw(intentData.intent()); |
| 204 | break; |
| 205 | default: |
Jonathan Hart | aae93b2 | 2015-07-22 14:59:47 -0700 | [diff] [blame] | 206 | log.warn("Trying to resubmit corrupt/failed intent {} in state {} with request {}", |
Brian O'Connor | b55d6e6 | 2015-06-01 15:25:53 -0700 | [diff] [blame] | 207 | intentData.key(), intentData.state(), intentData.request()); |
Brian O'Connor | a6c9b5c | 2015-04-29 22:38:29 -0700 | [diff] [blame] | 208 | break; |
| 209 | } |
| 210 | } |
| 211 | |
| 212 | private void resubmitPendingRequest(IntentData intentData) { |
Brian O'Connor | 3822430 | 2016-08-02 22:03:01 -0700 | [diff] [blame] | 213 | // FIXME should we back off here? |
Brian O'Connor | a6c9b5c | 2015-04-29 22:38:29 -0700 | [diff] [blame] | 214 | switch (intentData.request()) { |
| 215 | case INSTALL_REQ: |
Brian O'Connor | a6c9b5c | 2015-04-29 22:38:29 -0700 | [diff] [blame] | 216 | case WITHDRAW_REQ: |
Brian O'Connor | 105cf53 | 2016-04-19 13:07:38 -0700 | [diff] [blame] | 217 | case PURGE_REQ: |
jaegonkim | cbe1c5e | 2018-05-20 15:11:18 +0900 | [diff] [blame] | 218 | service.addPending(IntentData.copy(intentData, new WallClockTimestamp())); |
Brian O'Connor | 105cf53 | 2016-04-19 13:07:38 -0700 | [diff] [blame] | 219 | break; |
Brian O'Connor | a6c9b5c | 2015-04-29 22:38:29 -0700 | [diff] [blame] | 220 | default: |
Brian O'Connor | c90d184 | 2015-10-01 15:48:00 -0700 | [diff] [blame] | 221 | log.warn("Failed to resubmit pending intent {} in state {} with request {}", |
Brian O'Connor | b55d6e6 | 2015-06-01 15:25:53 -0700 | [diff] [blame] | 222 | intentData.key(), intentData.state(), intentData.request()); |
Brian O'Connor | a6c9b5c | 2015-04-29 22:38:29 -0700 | [diff] [blame] | 223 | break; |
| 224 | } |
| 225 | } |
| 226 | |
Brian O'Connor | 3c58e96 | 2015-04-28 23:21:51 -0700 | [diff] [blame] | 227 | /** |
Jonathan Hart | aae93b2 | 2015-07-22 14:59:47 -0700 | [diff] [blame] | 228 | * Iterates through corrupt, failed and pending intents and |
| 229 | * re-submit/withdraw appropriately. |
Brian O'Connor | 3c58e96 | 2015-04-28 23:21:51 -0700 | [diff] [blame] | 230 | */ |
| 231 | private void cleanup() { |
Pier Luigi | e6caf68 | 2017-01-26 15:25:09 -0800 | [diff] [blame] | 232 | int corruptCount = 0, failedCount = 0, stuckCount = 0, pendingCount = 0, skipped = 0; |
Jonathan Hart | aae93b2 | 2015-07-22 14:59:47 -0700 | [diff] [blame] | 233 | |
Brian O'Connor | c590ebb | 2016-12-08 18:16:41 -0800 | [diff] [blame] | 234 | // Check the pending map first, because the check of the current map |
| 235 | // will add items to the pending map. |
| 236 | for (IntentData intentData : store.getPendingData(true, periodMs)) { |
Pier Luigi | 13b287f | 2017-01-10 15:07:52 -0800 | [diff] [blame] | 237 | log.debug("Resubmit Pending Intent: key {}, state {}, request {}", |
| 238 | intentData.key(), intentData.state(), intentData.request()); |
Brian O'Connor | c590ebb | 2016-12-08 18:16:41 -0800 | [diff] [blame] | 239 | resubmitPendingRequest(intentData); |
| 240 | pendingCount++; |
| 241 | } |
| 242 | |
Brian O'Connor | a6c9b5c | 2015-04-29 22:38:29 -0700 | [diff] [blame] | 243 | for (IntentData intentData : store.getIntentData(true, periodMs)) { |
jaegonkim | ab7e59f | 2018-05-07 13:04:05 +0900 | [diff] [blame] | 244 | IntentData pendingIntentData = store.getPendingData(intentData.key()); |
| 245 | if (pendingIntentData != null) { |
| 246 | continue; |
| 247 | } |
| 248 | |
Brian O'Connor | a6c9b5c | 2015-04-29 22:38:29 -0700 | [diff] [blame] | 249 | switch (intentData.state()) { |
Jonathan Hart | aae93b2 | 2015-07-22 14:59:47 -0700 | [diff] [blame] | 250 | case FAILED: |
Pier Luigi | 13b287f | 2017-01-10 15:07:52 -0800 | [diff] [blame] | 251 | log.debug("Resubmit Failed Intent: key {}, state {}, request {}", |
jaegonkim | ab7e59f | 2018-05-07 13:04:05 +0900 | [diff] [blame] | 252 | intentData.key(), intentData.state(), intentData.request()); |
Jonathan Hart | aae93b2 | 2015-07-22 14:59:47 -0700 | [diff] [blame] | 253 | resubmitCorrupt(intentData, false); |
| 254 | failedCount++; |
| 255 | break; |
Brian O'Connor | a6c9b5c | 2015-04-29 22:38:29 -0700 | [diff] [blame] | 256 | case CORRUPT: |
Pier Luigi | 13b287f | 2017-01-10 15:07:52 -0800 | [diff] [blame] | 257 | log.debug("Resubmit Corrupt Intent: key {}, state {}, request {}", |
jaegonkim | ab7e59f | 2018-05-07 13:04:05 +0900 | [diff] [blame] | 258 | intentData.key(), intentData.state(), intentData.request()); |
Brian O'Connor | a6c9b5c | 2015-04-29 22:38:29 -0700 | [diff] [blame] | 259 | resubmitCorrupt(intentData, false); |
| 260 | corruptCount++; |
Brian O'Connor | eba4e34 | 2015-04-30 22:50:13 -0700 | [diff] [blame] | 261 | break; |
Brian O'Connor | a6c9b5c | 2015-04-29 22:38:29 -0700 | [diff] [blame] | 262 | case INSTALLING: //FALLTHROUGH |
| 263 | case WITHDRAWING: |
Pier Luigi | e6caf68 | 2017-01-26 15:25:09 -0800 | [diff] [blame] | 264 | // Instances can have different clocks and potentially we can have problems |
| 265 | // An Intent can be submitted again before the real period of the stuck intents |
| 266 | final WallClockTimestamp time = new WallClockTimestamp( |
| 267 | System.currentTimeMillis() - periodMsForStuck |
| 268 | ); |
| 269 | if (intentData.version().isOlderThan(time)) { |
| 270 | resubmitPendingRequest(intentData); |
| 271 | stuckCount++; |
| 272 | } else { |
| 273 | skipped++; |
| 274 | } |
Brian O'Connor | eba4e34 | 2015-04-30 22:50:13 -0700 | [diff] [blame] | 275 | break; |
Brian O'Connor | a6c9b5c | 2015-04-29 22:38:29 -0700 | [diff] [blame] | 276 | default: |
| 277 | //NOOP |
| 278 | break; |
Brian O'Connor | 3c58e96 | 2015-04-28 23:21:51 -0700 | [diff] [blame] | 279 | } |
| 280 | } |
Brian O'Connor | a6c9b5c | 2015-04-29 22:38:29 -0700 | [diff] [blame] | 281 | |
Jonathan Hart | 82efa69 | 2015-10-10 18:30:28 -0700 | [diff] [blame] | 282 | if (corruptCount + failedCount + stuckCount + pendingCount > 0) { |
| 283 | log.debug("Intent cleanup ran and resubmitted {} corrupt, {} failed, {} stuck, and {} pending intents", |
| 284 | corruptCount, failedCount, stuckCount, pendingCount); |
| 285 | } |
Pier Luigi | e6caf68 | 2017-01-26 15:25:09 -0800 | [diff] [blame] | 286 | if (skipped > 0) { |
| 287 | log.debug("Intent cleanup skipped {} intents", skipped); |
| 288 | } |
Brian O'Connor | 3c58e96 | 2015-04-28 23:21:51 -0700 | [diff] [blame] | 289 | } |
| 290 | |
| 291 | @Override |
| 292 | public void event(IntentEvent event) { |
Brian O'Connor | 6d8e317 | 2015-04-30 15:43:57 -0700 | [diff] [blame] | 293 | // this is the fast path for CORRUPT intents, retry on event notification. |
Brian O'Connor | a6c9b5c | 2015-04-29 22:38:29 -0700 | [diff] [blame] | 294 | //TODO we might consider using the timer to back off for subsequent retries |
Brian O'Connor | 5fcf6f5 | 2015-05-28 17:34:26 -0700 | [diff] [blame] | 295 | if (enabled && event.type() == IntentEvent.Type.CORRUPT) { |
Brian O'Connor | a6c9b5c | 2015-04-29 22:38:29 -0700 | [diff] [blame] | 296 | Key key = event.subject().key(); |
| 297 | if (store.isMaster(key)) { |
| 298 | IntentData data = store.getIntentData(event.subject().key()); |
| 299 | resubmitCorrupt(data, true); |
| 300 | } |
Brian O'Connor | 3c58e96 | 2015-04-28 23:21:51 -0700 | [diff] [blame] | 301 | } |
| 302 | } |
| 303 | } |