Return null instead of throw exception for invalid event states.

Change-Id: Ie40ca4dc1c241aa4f27652aa4e8b3f99eb924169
diff --git a/core/api/src/main/java/org/onosproject/net/intent/IntentEvent.java b/core/api/src/main/java/org/onosproject/net/intent/IntentEvent.java
index b1571ad..3b7c6c6 100644
--- a/core/api/src/main/java/org/onosproject/net/intent/IntentEvent.java
+++ b/core/api/src/main/java/org/onosproject/net/intent/IntentEvent.java
@@ -72,10 +72,26 @@
         super(type, intent);
     }
 
+    /**
+     * Creates an IntentEvent based on the state contained in the given intent
+     * data. Some states are not sent as external events, and these states will
+     * return null events.
+     *
+     * @param data the intent data to create an event for
+     * @return new intent event if the state is valid, otherwise null.
+     */
     public static IntentEvent getEvent(IntentData data) {
         return getEvent(data.state(), data.intent());
     }
 
+    /**
+     * Creates an IntentEvent based on the given state and intent. Some states
+     * are not sent as external events, and these states will return null events.
+     *
+     * @param state new state of the intent
+     * @param intent intent to put in event
+     * @return new intent event if the state is valid, otherwise null.
+     */
     public static IntentEvent getEvent(IntentState state, Intent intent) {
         Type type;
         switch (state) {
@@ -95,14 +111,13 @@
                 type = Type.FAILED;
                 break;
 
-            //fallthrough to default from here
+            // fallthrough to default from here
             case COMPILING:
             case INSTALLING:
             case RECOMPILING:
             case WITHDRAWING:
             default:
-                throw new IllegalArgumentException(
-                        "Intent event cannot have transient state: " + state);
+                return null;
         }
         return new IntentEvent(type, intent);
     }
diff --git a/core/store/dist/src/main/java/org/onosproject/store/intent/impl/GossipIntentStore.java b/core/store/dist/src/main/java/org/onosproject/store/intent/impl/GossipIntentStore.java
index c78b5f9..6ddf58f 100644
--- a/core/store/dist/src/main/java/org/onosproject/store/intent/impl/GossipIntentStore.java
+++ b/core/store/dist/src/main/java/org/onosproject/store/intent/impl/GossipIntentStore.java
@@ -268,9 +268,8 @@
 
     @Override
     public void addPending(IntentData data) {
-        log.debug("new call to pending {}", data);
+        log.debug("new pending {} {} {}", data.key(), data.state(), data.version());
         if (data.version() == null) {
-            log.debug("updating timestamp");
             data.setVersion(new SystemClockTimestamp());
         }
         pending.put(data.key(), copyData(data));
@@ -293,16 +292,9 @@
         public void event(
                 EventuallyConsistentMapEvent<Key, IntentData> event) {
             if (event.type() == EventuallyConsistentMapEvent.Type.PUT) {
-                IntentEvent externalEvent;
                 IntentData intentData = event.value();
 
-                try {
-                    externalEvent = IntentEvent.getEvent(intentData.state(), intentData.intent());
-                } catch (IllegalArgumentException e) {
-                    externalEvent = null;
-                }
-
-                notifyDelegateIfNotNull(externalEvent);
+                notifyDelegateIfNotNull(IntentEvent.getEvent(intentData));
             }
         }
     }
@@ -322,12 +314,7 @@
                     }
                 }
 
-                try {
-                    notifyDelegate(IntentEvent.getEvent(event.value()));
-                } catch (IllegalArgumentException e) {
-                    //no-op
-                    log.trace("ignore this exception: {}", e);
-                }
+                notifyDelegateIfNotNull(IntentEvent.getEvent(event.value()));
             }
         }
     }
diff --git a/core/store/dist/src/main/java/org/onosproject/store/intent/impl/SimpleIntentStore.java b/core/store/dist/src/main/java/org/onosproject/store/intent/impl/SimpleIntentStore.java
index 2bc5b63..8778e93 100644
--- a/core/store/dist/src/main/java/org/onosproject/store/intent/impl/SimpleIntentStore.java
+++ b/core/store/dist/src/main/java/org/onosproject/store/intent/impl/SimpleIntentStore.java
@@ -198,16 +198,17 @@
                     pending.remove(newData.key());
                 }
 
-                try {
-                    notifyDelegate(IntentEvent.getEvent(newData));
-                } catch (IllegalArgumentException e) {
-                    //no-op
-                    log.trace("ignore this exception: {}", e);
-                }
+                notifyDelegateIfNotNull(IntentEvent.getEvent(newData));
             }
         }
     }
 
+    private void notifyDelegateIfNotNull(IntentEvent event) {
+        if (event != null) {
+            notifyDelegate(event);
+        }
+    }
+
     @Override
     public void batchWrite(Iterable<IntentData> updates) {
         for (IntentData data : updates) {
@@ -241,7 +242,7 @@
                 pending.put(data.key(), data);
                 checkNotNull(delegate, "Store delegate is not set")
                         .process(data);
-                notifyDelegate(IntentEvent.getEvent(data));
+                notifyDelegateIfNotNull(IntentEvent.getEvent(data));
             } else {
                 log.debug("IntentData {} is older than existing: {}",
                           data, existingData);