Ensure all Intents reaches installable state.

Previousely, there was an implicit assumption that
all Intent will reach installable state at same # of compilation steps.

ONOS-5855 opened a possibility for an Intent to be compiled down to
multiple kind of installables.
As a result, assumption that all Intents will reach installable
state after same # of compilation steps is likely to break.

This patch will wait for all compilation result to reach installable.

Change-Id: I307f39b660b586fc4cd98be9d1212c32163f0a90
diff --git a/core/net/src/main/java/org/onosproject/net/intent/impl/CompilerRegistry.java b/core/net/src/main/java/org/onosproject/net/intent/impl/CompilerRegistry.java
index b16a7d5..29d5a5f 100644
--- a/core/net/src/main/java/org/onosproject/net/intent/impl/CompilerRegistry.java
+++ b/core/net/src/main/java/org/onosproject/net/intent/impl/CompilerRegistry.java
@@ -23,8 +23,10 @@
 import org.onosproject.net.intent.IntentException;
 
 import java.util.ArrayList;
+import java.util.LinkedList;
 import java.util.List;
 import java.util.Map;
+import java.util.Queue;
 import java.util.concurrent.ConcurrentHashMap;
 import java.util.concurrent.ConcurrentMap;
 
@@ -76,13 +78,27 @@
             return ImmutableList.of(intent);
         }
 
-        registerSubclassCompilerIfNeeded(intent);
         // FIXME: get previous resources
-        List<Intent> installable = new ArrayList<>();
-        for (Intent compiled : getCompiler(intent).compile(intent, previousInstallables)) {
-            installable.addAll(compile(compiled, previousInstallables));
+        List<Intent> installables = new ArrayList<>();
+        Queue<Intent> compileQueue = new LinkedList<>();
+        compileQueue.add(intent);
+
+        Intent compiling;
+        while ((compiling = compileQueue.poll()) != null) {
+            registerSubclassCompilerIfNeeded(compiling);
+
+            List<Intent> compiled = getCompiler(compiling)
+                                     .compile(compiling, previousInstallables);
+
+            compiled.forEach(i -> {
+                if (i.isInstallable()) {
+                    installables.add(i);
+                } else {
+                    compileQueue.add(i);
+                }
+            });
         }
-        return installable;
+        return installables;
     }
 
     /**