Showing
5 changed files
with
38 additions
and
13 deletions
... | @@ -35,7 +35,7 @@ public class DevicesListCommand extends AbstractShellCommand { | ... | @@ -35,7 +35,7 @@ public class DevicesListCommand extends AbstractShellCommand { |
35 | * @param service device service | 35 | * @param service device service |
36 | * @return sorted device list | 36 | * @return sorted device list |
37 | */ | 37 | */ |
38 | - protected List<Device> getSortedDevices(DeviceService service) { | 38 | + protected static List<Device> getSortedDevices(DeviceService service) { |
39 | List<Device> devices = newArrayList(service.getDevices()); | 39 | List<Device> devices = newArrayList(service.getDevices()); |
40 | Collections.sort(devices, Comparators.ELEMENT_COMPARATOR); | 40 | Collections.sort(devices, Comparators.ELEMENT_COMPARATOR); |
41 | return devices; | 41 | return devices; | ... | ... |
1 | package org.onlab.onos.cli.net; | 1 | package org.onlab.onos.cli.net; |
2 | 2 | ||
3 | import static com.google.common.collect.Lists.newArrayList; | 3 | import static com.google.common.collect.Lists.newArrayList; |
4 | +import static org.onlab.onos.cli.net.DevicesListCommand.getSortedDevices; | ||
4 | 5 | ||
5 | import java.util.Collections; | 6 | import java.util.Collections; |
6 | import java.util.List; | 7 | import java.util.List; |
... | @@ -64,7 +65,7 @@ public class FlowsListCommand extends AbstractShellCommand { | ... | @@ -64,7 +65,7 @@ public class FlowsListCommand extends AbstractShellCommand { |
64 | if (state != null && !state.equals("any")) { | 65 | if (state != null && !state.equals("any")) { |
65 | s = FlowEntryState.valueOf(state.toUpperCase()); | 66 | s = FlowEntryState.valueOf(state.toUpperCase()); |
66 | } | 67 | } |
67 | - Iterable<Device> devices = uri == null ? deviceService.getDevices() : | 68 | + Iterable<Device> devices = uri == null ? getSortedDevices(deviceService) : |
68 | Collections.singletonList(deviceService.getDevice(DeviceId.deviceId(uri))); | 69 | Collections.singletonList(deviceService.getDevice(DeviceId.deviceId(uri))); |
69 | for (Device d : devices) { | 70 | for (Device d : devices) { |
70 | if (s == null) { | 71 | if (s == null) { | ... | ... |
... | @@ -128,7 +128,7 @@ public class FakeIntentManager implements TestableIntentService { | ... | @@ -128,7 +128,7 @@ public class FakeIntentManager implements TestableIntentService { |
128 | setState(intent, IntentState.WITHDRAWN); | 128 | setState(intent, IntentState.WITHDRAWN); |
129 | dispatch(new IntentEvent(IntentEvent.Type.WITHDRAWN, intent)); | 129 | dispatch(new IntentEvent(IntentEvent.Type.WITHDRAWN, intent)); |
130 | } catch (IntentException e) { | 130 | } catch (IntentException e) { |
131 | - // FIXME: Do we really want to do this? | 131 | + // FIXME: Rework this to always go from WITHDRAWING to WITHDRAWN! |
132 | setState(intent, IntentState.FAILED); | 132 | setState(intent, IntentState.FAILED); |
133 | dispatch(new IntentEvent(IntentEvent.Type.FAILED, intent)); | 133 | dispatch(new IntentEvent(IntentEvent.Type.FAILED, intent)); |
134 | } | 134 | } | ... | ... |
... | @@ -36,6 +36,7 @@ import java.util.concurrent.ExecutorService; | ... | @@ -36,6 +36,7 @@ import java.util.concurrent.ExecutorService; |
36 | import static com.google.common.base.Preconditions.checkNotNull; | 36 | import static com.google.common.base.Preconditions.checkNotNull; |
37 | import static java.util.concurrent.Executors.newSingleThreadExecutor; | 37 | import static java.util.concurrent.Executors.newSingleThreadExecutor; |
38 | import static org.onlab.onos.net.intent.IntentState.*; | 38 | import static org.onlab.onos.net.intent.IntentState.*; |
39 | +import static org.onlab.util.Tools.delay; | ||
39 | import static org.onlab.util.Tools.namedThreads; | 40 | import static org.onlab.util.Tools.namedThreads; |
40 | import static org.slf4j.LoggerFactory.getLogger; | 41 | import static org.slf4j.LoggerFactory.getLogger; |
41 | 42 | ||
... | @@ -226,6 +227,8 @@ public class IntentManager | ... | @@ -226,6 +227,8 @@ public class IntentManager |
226 | executeInstallingPhase(intent); | 227 | executeInstallingPhase(intent); |
227 | 228 | ||
228 | } catch (Exception e) { | 229 | } catch (Exception e) { |
230 | + log.warn("Unable to compile intent {} due to: {}", intent.id(), e); | ||
231 | + | ||
229 | // If compilation failed, mark the intent as failed. | 232 | // If compilation failed, mark the intent as failed. |
230 | store.setState(intent, FAILED); | 233 | store.setState(intent, FAILED); |
231 | } | 234 | } |
... | @@ -238,8 +241,6 @@ public class IntentManager | ... | @@ -238,8 +241,6 @@ public class IntentManager |
238 | for (Intent compiled : getCompiler(intent).compile(intent)) { | 241 | for (Intent compiled : getCompiler(intent).compile(intent)) { |
239 | InstallableIntent installableIntent = (InstallableIntent) compiled; | 242 | InstallableIntent installableIntent = (InstallableIntent) compiled; |
240 | installable.add(installableIntent); | 243 | installable.add(installableIntent); |
241 | - trackerService.addTrackedResources(intent.id(), | ||
242 | - installableIntent.requiredLinks()); | ||
243 | } | 244 | } |
244 | return installable; | 245 | return installable; |
245 | } | 246 | } |
... | @@ -259,12 +260,17 @@ public class IntentManager | ... | @@ -259,12 +260,17 @@ public class IntentManager |
259 | if (installables != null) { | 260 | if (installables != null) { |
260 | for (InstallableIntent installable : installables) { | 261 | for (InstallableIntent installable : installables) { |
261 | registerSubclassInstallerIfNeeded(installable); | 262 | registerSubclassInstallerIfNeeded(installable); |
263 | + trackerService.addTrackedResources(intent.id(), | ||
264 | + installable.requiredLinks()); | ||
262 | getInstaller(installable).install(installable); | 265 | getInstaller(installable).install(installable); |
263 | } | 266 | } |
264 | } | 267 | } |
265 | eventDispatcher.post(store.setState(intent, INSTALLED)); | 268 | eventDispatcher.post(store.setState(intent, INSTALLED)); |
266 | 269 | ||
267 | } catch (Exception e) { | 270 | } catch (Exception e) { |
271 | + log.warn("Unable to install intent {} due to: {}", intent.id(), e); | ||
272 | + uninstallIntent(intent); | ||
273 | + | ||
268 | // If compilation failed, kick off the recompiling phase. | 274 | // If compilation failed, kick off the recompiling phase. |
269 | executeRecompilingPhase(intent); | 275 | executeRecompilingPhase(intent); |
270 | } | 276 | } |
... | @@ -299,6 +305,8 @@ public class IntentManager | ... | @@ -299,6 +305,8 @@ public class IntentManager |
299 | executeInstallingPhase(intent); | 305 | executeInstallingPhase(intent); |
300 | } | 306 | } |
301 | } catch (Exception e) { | 307 | } catch (Exception e) { |
308 | + log.warn("Unable to recompile intent {} due to: {}", intent.id(), e); | ||
309 | + | ||
302 | // If compilation failed, mark the intent as failed. | 310 | // If compilation failed, mark the intent as failed. |
303 | eventDispatcher.post(store.setState(intent, FAILED)); | 311 | eventDispatcher.post(store.setState(intent, FAILED)); |
304 | } | 312 | } |
... | @@ -313,12 +321,7 @@ public class IntentManager | ... | @@ -313,12 +321,7 @@ public class IntentManager |
313 | private void executeWithdrawingPhase(Intent intent) { | 321 | private void executeWithdrawingPhase(Intent intent) { |
314 | // Indicate that the intent is being withdrawn. | 322 | // Indicate that the intent is being withdrawn. |
315 | store.setState(intent, WITHDRAWING); | 323 | store.setState(intent, WITHDRAWING); |
316 | - List<InstallableIntent> installables = store.getInstallableIntents(intent.id()); | 324 | + uninstallIntent(intent); |
317 | - if (installables != null) { | ||
318 | - for (InstallableIntent installable : installables) { | ||
319 | - getInstaller(installable).uninstall(installable); | ||
320 | - } | ||
321 | - } | ||
322 | 325 | ||
323 | // If all went well, disassociate the top-level intent with its | 326 | // If all went well, disassociate the top-level intent with its |
324 | // installable derivatives and mark it as withdrawn. | 327 | // installable derivatives and mark it as withdrawn. |
... | @@ -327,6 +330,24 @@ public class IntentManager | ... | @@ -327,6 +330,24 @@ public class IntentManager |
327 | } | 330 | } |
328 | 331 | ||
329 | /** | 332 | /** |
333 | + * Uninstalls all installable intents associated with the given intent. | ||
334 | + * | ||
335 | + * @param intent intent to be uninstalled | ||
336 | + */ | ||
337 | + private void uninstallIntent(Intent intent) { | ||
338 | + try { | ||
339 | + List<InstallableIntent> installables = store.getInstallableIntents(intent.id()); | ||
340 | + if (installables != null) { | ||
341 | + for (InstallableIntent installable : installables) { | ||
342 | + getInstaller(installable).uninstall(installable); | ||
343 | + } | ||
344 | + } | ||
345 | + } catch (IntentException e) { | ||
346 | + log.warn("Unable to uninstall intent {} due to: {}", intent.id(), e); | ||
347 | + } | ||
348 | + } | ||
349 | + | ||
350 | + /** | ||
330 | * Registers an intent compiler of the specified intent if an intent compiler | 351 | * Registers an intent compiler of the specified intent if an intent compiler |
331 | * for the intent is not registered. This method traverses the class hierarchy of | 352 | * for the intent is not registered. This method traverses the class hierarchy of |
332 | * the intent. Once an intent compiler for a parent type is found, this method | 353 | * the intent. Once an intent compiler for a parent type is found, this method |
... | @@ -394,7 +415,10 @@ public class IntentManager | ... | @@ -394,7 +415,10 @@ public class IntentManager |
394 | boolean compileAllFailed) { | 415 | boolean compileAllFailed) { |
395 | // Attempt recompilation of the specified intents first. | 416 | // Attempt recompilation of the specified intents first. |
396 | for (IntentId intentId : intentIds) { | 417 | for (IntentId intentId : intentIds) { |
397 | - executeRecompilingPhase(getIntent(intentId)); | 418 | + Intent intent = getIntent(intentId); |
419 | + uninstallIntent(intent); | ||
420 | + delay(1000); | ||
421 | + executeRecompilingPhase(intent); | ||
398 | } | 422 | } |
399 | 423 | ||
400 | if (compileAllFailed) { | 424 | if (compileAllFailed) { | ... | ... |
... | @@ -113,7 +113,7 @@ public class ObjectiveTracker implements ObjectiveTrackerService { | ... | @@ -113,7 +113,7 @@ public class ObjectiveTracker implements ObjectiveTrackerService { |
113 | @Override | 113 | @Override |
114 | public void run() { | 114 | public void run() { |
115 | if (event.reasons() == null) { | 115 | if (event.reasons() == null) { |
116 | - delegate.triggerCompile(null, false); | 116 | + delegate.triggerCompile(null, true); |
117 | 117 | ||
118 | } else { | 118 | } else { |
119 | Set<IntentId> toBeRecompiled = new HashSet<>(); | 119 | Set<IntentId> toBeRecompiled = new HashSet<>(); | ... | ... |
-
Please register or login to post a comment