adding some logging and checking Intent type more carefully

Checking for switch == null when install flow entries
(effect is we only install fe's on switches for which we are master)

Change-Id: I1645caf68ec6082737157737f3e12752a7515f5d
diff --git a/src/main/java/net/onrc/onos/intent/runtime/PlanCalcRuntime.java b/src/main/java/net/onrc/onos/intent/runtime/PlanCalcRuntime.java
index 2e0c563..37ad7a2 100644
--- a/src/main/java/net/onrc/onos/intent/runtime/PlanCalcRuntime.java
+++ b/src/main/java/net/onrc/onos/intent/runtime/PlanCalcRuntime.java
@@ -9,6 +9,9 @@
 import java.util.Map;
 import java.util.Set;
 
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
 import net.floodlightcontroller.util.MACAddress;
 import net.onrc.onos.intent.FlowEntry;
 import net.onrc.onos.intent.Intent;
@@ -29,6 +32,7 @@
 public class PlanCalcRuntime {
 
 //    NetworkGraph graph;
+    private final static Logger log = LoggerFactory.getLogger(PlanCalcRuntime.class);
 
     public PlanCalcRuntime(/*NetworkGraph graph*/) {
 //	this.graph = graph;
@@ -42,6 +46,10 @@
     private Set<Collection<FlowEntry>> computeFlowEntries(IntentOperationList intentOps) {
 	Set<Collection<FlowEntry>> flowEntries = new HashSet<>();
 	for(IntentOperation i : intentOps) {
+	    if(!(i.intent instanceof PathIntent)) {
+		log.warn("Not a path intent: {}", i);
+		continue;
+	    }
 	    PathIntent intent = (PathIntent) i.intent;
 	    Intent parent = intent.getParentIntent();
 	    long srcPort, dstPort;
@@ -60,7 +68,7 @@
 		lastDstPort = pathIntent.getDstPortNumber();
 	    }
 	    else {
-		// TODO: log this error
+		log.warn("Unsupported Intent: {}", parent);
 		continue;
 	    }
 	    List<FlowEntry> entries = new ArrayList<>();
diff --git a/src/main/java/net/onrc/onos/intent/runtime/PlanInstallModule.java b/src/main/java/net/onrc/onos/intent/runtime/PlanInstallModule.java
index adef594..4d4e437 100644
--- a/src/main/java/net/onrc/onos/intent/runtime/PlanInstallModule.java
+++ b/src/main/java/net/onrc/onos/intent/runtime/PlanInstallModule.java
@@ -67,7 +67,8 @@
 	    while(true) {
 		try {
 		    IntentOperationList intents = intentQueue.take();
-		    //TODO: drain the remaining intent lists
+		    //TODO: consider draining the remaining intent lists 
+		    //      and processing in one big batch
 		    processIntents(intents);
 		} catch (InterruptedException e) {
 		    log.warn("Error taking from intent queue: {}", e.getMessage());
@@ -162,13 +163,13 @@
     
     @Override
     public Collection<Class<? extends IFloodlightService>> getModuleServices() {
-	// TODO Auto-generated method stub
+	// no services, for now
 	return null;
     }
 
     @Override
     public Map<Class<? extends IFloodlightService>, IFloodlightService> getServiceImpls() {
-	// TODO Auto-generated method stub
+	// no services, for now
 	return null;
     }
 
diff --git a/src/main/java/net/onrc/onos/intent/runtime/PlanInstallRuntime.java b/src/main/java/net/onrc/onos/intent/runtime/PlanInstallRuntime.java
index 4325c4e..844e620 100644
--- a/src/main/java/net/onrc/onos/intent/runtime/PlanInstallRuntime.java
+++ b/src/main/java/net/onrc/onos/intent/runtime/PlanInstallRuntime.java
@@ -40,14 +40,25 @@
 	log.debug("IOFSwitches: {}", switches);
 	for(Set<FlowEntry> phase : plan) {
 	    Set<Pair<IOFSwitch, net.onrc.onos.ofcontroller.util.FlowEntry>> entries = new HashSet<>();
+	    Set<IOFSwitch> modifiedSwitches = new HashSet<>();
+
 	    // convert flow entries and create pairs
 	    for(FlowEntry entry : phase) {
 		IOFSwitch sw = switches.get(entry.getSwitch());
+		if(sw == null) {
+		    // no active switch, skip this flow entry
+		    log.debug("Skipping flow entry: {}", entry);
+		    continue;
+		}
 		entries.add(new Pair<>(sw, entry.getFlowEntry()));
+		modifiedSwitches.add(sw);
 	    }
-	    log.debug("Pushing flow entries: {}", entries);
+	    
 	    // push flow entries to switches
+	    log.debug("Pushing flow entries: {}", entries);
 	    pusher.pushFlowEntries(entries);
+	    
+	    // TODO: insert a barrier after each phase on each modifiedSwitch
 	    // TODO: wait for confirmation messages before proceeding
 	}
 	// TODO: we assume that the plan installation succeeds for now