Improvements to Intent Framework to allow intents to be installed end to end.

Change-Id: I7256e31c745e2c36270ab7f25378a94e20664c34
diff --git a/src/main/java/net/onrc/onos/api/flowmanager/PacketPathFlow.java b/src/main/java/net/onrc/onos/api/flowmanager/PacketPathFlow.java
index 34d6776..5377862 100644
--- a/src/main/java/net/onrc/onos/api/flowmanager/PacketPathFlow.java
+++ b/src/main/java/net/onrc/onos/api/flowmanager/PacketPathFlow.java
@@ -3,6 +3,7 @@
 import static com.google.common.base.Preconditions.checkNotNull;
 import static com.google.common.base.Preconditions.checkState;
 
+import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Iterator;
 import java.util.LinkedList;
@@ -139,8 +140,11 @@
         List<SwitchPort> portList = new LinkedList<>();
         for (FlowLink link : path) {
             portList.add(link.getDstSwitchPort());
-            actionsList.add(Arrays.asList(
-                    (Action) new OutputAction(link.getSrcPortNumber())));
+            List<Action> l = new ArrayList<Action>();
+            l.add(new OutputAction(link.getSrcPortNumber()));
+            actionsList.add(l);
+            // Arrays.asList(
+            // (Action) new OutputAction(link.getSrcPortNumber())));
         }
 
         // The head switch's ingress port
diff --git a/src/main/java/net/onrc/onos/core/matchaction/MatchActionComponent.java b/src/main/java/net/onrc/onos/core/matchaction/MatchActionComponent.java
index 0307d4c..3ee164f 100644
--- a/src/main/java/net/onrc/onos/core/matchaction/MatchActionComponent.java
+++ b/src/main/java/net/onrc/onos/core/matchaction/MatchActionComponent.java
@@ -50,7 +50,7 @@
     private final BlockingQueue<MatchActionOperationsId> resolvedQueue = new ArrayBlockingQueue<>(100);
     private final BlockingQueue<MatchActionOperations> installationWorkQueue = new ArrayBlockingQueue<>(100);
 
-    private IEventChannel<String, MatchActionOperations> installSetChannel;
+    private IEventChannel<Long, MatchActionOperations> installSetChannel;
     private IEventChannel<String, SwitchResultList> installSetReplyChannel;
 
     private final IDatagridService datagrid;
@@ -88,23 +88,26 @@
         matchActionOperationsIdGenerator =
                 new MatchActionOperationsIdGeneratorWithIdBlockAllocator(idBlockAllocator);
 
-        installSetChannel = datagrid.createChannel("onos.matchaction.installSetChannel",
-                String.class,
+        final Installer installerListener = new Installer();
+        installSetChannel = datagrid.addListener(
+                "onos.matchaction.installSetChannel",
+                installerListener,
+                Long.class,
                 MatchActionOperations.class);
 
-        installSetReplyChannel = datagrid.createChannel("onos.matchaction.installSetReplyChannel",
+
+        final Coordinator coordinator = new Coordinator();
+        coordinator.start();
+        installSetReplyChannel = datagrid.addListener(
+                "onos.matchaction.installSetReplyChannel",
+                coordinator,
                 String.class,
                 SwitchResultList.class);
 
-        final Thread coordinator = new Coordinator();
-        coordinator.start();
-
         // TODO Single instance for now, should be a work queue of some sort eventually
-        final Thread installer = new InstallerWorker();
+        final InstallerWorker installer = new InstallerWorker();
         installer.start();
 
-        final Installer installerListener = new Installer();
-        installerListener.start();
     }
 
     /**
@@ -175,7 +178,7 @@
          * Default constructor.
          */
         Coordinator() {
-            installSetReplyChannel.addListener(this);
+            // nothing to initialize
         }
 
         @Override
@@ -228,7 +231,8 @@
             pendingMatchActionOperations.put(setId, switches);
 
             // distribute apply/undo sets to cluster
-            installSetChannel.addTransientEntry(setId.toString(), matchSet);
+            log.trace("MatchAction Coordinator distributing set: {}", matchSet);
+            installSetChannel.addTransientEntry(setId.getId(), matchSet);
         }
 
         @Override
@@ -404,20 +408,12 @@
      * InstallerWorker threads.
      */
     class Installer
-            implements IEventChannelListener<String, MatchActionOperations> {
-
-        /**
-         * Starts the Installer consumer.  Adds a listener on the MatchActionOperations
-         * channel.
-         */
-        private void start() {
-            installSetChannel.addListener(this);
-        }
-
+            implements IEventChannelListener<Long, MatchActionOperations> {
 
         @Override
         public void entryAdded(MatchActionOperations value) {
             try {
+                log.trace("MatchAction Installer receiving set: {}", value);
                 installationWorkQueue.put(value);
             } catch (InterruptedException e) {
                 log.warn("Error adding to installer work queue: {}",
@@ -433,6 +429,7 @@
         @Override
         public void entryUpdated(MatchActionOperations value) {
             try {
+                log.trace("MatchAction Installer receiving set: {}", value);
                 installationWorkQueue.put(value);
             } catch (InterruptedException e) {
                 log.warn("Error adding to installer work queue: {}",
diff --git a/src/main/java/net/onrc/onos/core/matchaction/MatchActionModule.java b/src/main/java/net/onrc/onos/core/matchaction/MatchActionModule.java
index 9bf1be4..8bf34a8 100644
--- a/src/main/java/net/onrc/onos/core/matchaction/MatchActionModule.java
+++ b/src/main/java/net/onrc/onos/core/matchaction/MatchActionModule.java
@@ -117,11 +117,13 @@
 
     @Override
     public void addEventListener(EventListener listener) {
-        throw new UnsupportedOperationException("events not implemented yet");
+        // TODO
+        log.warn("Could not add MatchAction EventListener: {}", listener);
     }
 
     @Override
     public void removeEventListener(EventListener listener) {
-        throw new UnsupportedOperationException("events not implemented yet");
+        // TODO
+        log.warn("Could not remove MatchAction EventListener: {}", listener);
     }
 }
diff --git a/src/main/java/net/onrc/onos/core/matchaction/MatchActionOperationsId.java b/src/main/java/net/onrc/onos/core/matchaction/MatchActionOperationsId.java
index a05dd90..3bf34d8 100644
--- a/src/main/java/net/onrc/onos/core/matchaction/MatchActionOperationsId.java
+++ b/src/main/java/net/onrc/onos/core/matchaction/MatchActionOperationsId.java
@@ -55,4 +55,9 @@
     public int hashCode() {
         return Objects.hashCode(id);
     }
+
+    @Override
+    public String toString() {
+        return "0x" + Long.toHexString(getId());
+    }
 }
diff --git a/src/main/java/net/onrc/onos/core/newintent/AbstractIntentInstaller.java b/src/main/java/net/onrc/onos/core/newintent/AbstractIntentInstaller.java
index b7aa6c9..d1c43c5 100644
--- a/src/main/java/net/onrc/onos/core/newintent/AbstractIntentInstaller.java
+++ b/src/main/java/net/onrc/onos/core/newintent/AbstractIntentInstaller.java
@@ -1,8 +1,12 @@
 package net.onrc.onos.core.newintent;
 
-import com.google.common.base.Optional;
-import com.google.common.base.Predicate;
-import com.google.common.collect.Iterables;
+import static com.google.common.base.Preconditions.checkNotNull;
+import static net.onrc.onos.api.flowmanager.FlowState.FAILED;
+import static net.onrc.onos.api.flowmanager.FlowState.INSTALLED;
+import static net.onrc.onos.api.flowmanager.FlowState.WITHDRAWN;
+
+import java.util.concurrent.CountDownLatch;
+
 import net.onrc.onos.api.flowmanager.Flow;
 import net.onrc.onos.api.flowmanager.FlowBatchHandle;
 import net.onrc.onos.api.flowmanager.FlowBatchStateChangedEvent;
@@ -16,12 +20,9 @@
 import net.onrc.onos.api.newintent.Intent;
 import net.onrc.onos.api.newintent.IntentInstaller;
 
-import java.util.concurrent.CountDownLatch;
-
-import static com.google.common.base.Preconditions.checkNotNull;
-import static net.onrc.onos.api.flowmanager.FlowState.FAILED;
-import static net.onrc.onos.api.flowmanager.FlowState.INSTALLED;
-import static net.onrc.onos.api.flowmanager.FlowState.WITHDRAWN;
+import com.google.common.base.Optional;
+import com.google.common.base.Predicate;
+import com.google.common.collect.Iterables;
 
 // TODO: consider naming because to call Flow manager's API will be removed
 // in long-term refactoring
@@ -53,16 +54,19 @@
             throw new IntentInstallationException("intent installation failed: " + intent);
         }
 
-        try {
-            listener.await();
-            if (listener.getFinalState() == FAILED) {
-                throw new IntentInstallationException("intent installation failed: " + intent);
-            }
-        } catch (InterruptedException e) {
-            throw new IntentInstallationException("intent installation failed: " + intent, e);
-        } finally {
-            flowManager.removeListener(listener);
-        }
+        // TODO (BOC) this blocks a Hazelcast thread, commenting out for now
+        // try {
+        // listener.await();
+        // if (listener.getFinalState() == FAILED) {
+        // throw new IntentInstallationException("intent installation failed: "
+        // + intent);
+        // }
+        // } catch (InterruptedException e) {
+        // throw new IntentInstallationException("intent installation failed: "
+        // + intent, e);
+        // } finally {
+        // flowManager.removeListener(listener);
+        // }
     }
 
     protected void removeFlow(Intent intent, Flow flow) {
diff --git a/src/main/java/net/onrc/onos/core/util/serializers/KryoFactory.java b/src/main/java/net/onrc/onos/core/util/serializers/KryoFactory.java
index 134f0d7..a19636b 100644
--- a/src/main/java/net/onrc/onos/core/util/serializers/KryoFactory.java
+++ b/src/main/java/net/onrc/onos/core/util/serializers/KryoFactory.java
@@ -57,6 +57,7 @@
 import net.onrc.onos.core.matchaction.SwitchResultList;
 import net.onrc.onos.core.matchaction.action.ModifyDstMacAction;
 import net.onrc.onos.core.matchaction.action.ModifySrcMacAction;
+import net.onrc.onos.core.matchaction.action.NullAction;
 import net.onrc.onos.core.matchaction.action.OutputAction;
 import net.onrc.onos.core.matchaction.match.PacketMatch;
 import net.onrc.onos.core.newintent.IntentCompilationResult;
@@ -289,6 +290,7 @@
         kryo.register(SwitchResultList.class);
         kryo.register(SwitchResult.class);
         kryo.register(SwitchResult.Status.class);
+        kryo.register(NullAction.class);
 
         // Host-related classes
         kryo.register(HashSet.class);