Fix for [ONOS-5825]

Changes:
- Adds exception management in the mgr;
- Improve logging of the clean up;

Change-Id: I3ca94761e5b4550b7f8df34e9de4a481bc546be3
diff --git a/core/net/src/main/java/org/onosproject/net/intent/impl/IntentManager.java b/core/net/src/main/java/org/onosproject/net/intent/impl/IntentManager.java
index d939f96..6f2ed13 100644
--- a/core/net/src/main/java/org/onosproject/net/intent/impl/IntentManager.java
+++ b/core/net/src/main/java/org/onosproject/net/intent/impl/IntentManager.java
@@ -433,9 +433,23 @@
                                 .thenApplyAsync(IntentProcessPhase::process, workerExecutor)
                                 .thenApply(FinalIntentProcessPhase::data)
                                 .exceptionally(e -> {
-                                    //FIXME
-                                    log.warn("Future failed: {}", e);
-                                    return null;
+                                    // When the future fails, we update the Intent to simulate the failure of
+                                    // the installation/withdrawal phase and we save in the current map. In
+                                    // the next round the CleanUp Thread will pick this Intent again.
+                                    log.warn("Future failed", e);
+                                    log.warn("Intent {} - state {} - request {}",
+                                             x.key(), x.state(), x.request());
+                                    switch (x.state()) {
+                                        case INSTALL_REQ:
+                                        case INSTALLING:
+                                        case WITHDRAW_REQ:
+                                        case WITHDRAWING:
+                                            x.setState(FAILED);
+                                            IntentData current = store.getIntentData(x.key());
+                                            return new IntentData(x, current.installables());
+                                        default:
+                                            return null;
+                                    }
                                 }))
                         .collect(Collectors.toList());