ONOS-6468 Fix for race condition between compilation and installation complete state.

- Fix for a bug where intent compilation complete state,
  can overwrites intent installation complete state,
  if intent installation completes before compilation complete state is written to the store.
  - Introduced internalState version on IntentData,
    which is effectively mutation count, in order to avoid
    batch write of compilation result overwriting installation result

Change-Id: I5d77dfbe496e690ebdf2b4f9643d2b64c4233182
diff --git a/core/net/src/main/java/org/onosproject/net/intent/impl/phase/Compiling.java b/core/net/src/main/java/org/onosproject/net/intent/impl/phase/Compiling.java
index bb82dfc..124d3fb 100644
--- a/core/net/src/main/java/org/onosproject/net/intent/impl/phase/Compiling.java
+++ b/core/net/src/main/java/org/onosproject/net/intent/impl/phase/Compiling.java
@@ -57,7 +57,7 @@
             List<Intent> compiled = processor.compile(data.intent(),
                     //TODO consider passing an optional here in the future
                     stored.map(IntentData::installables).orElse(null));
-            return Optional.of(new Installing(processor, new IntentData(data, compiled), stored));
+            return Optional.of(new Installing(processor, IntentData.compiled(data, compiled), stored));
         } catch (IntentException e) {
             log.warn("Unable to compile intent {} due to:", data.intent(), e);
             if (stored.filter(x -> !x.installables().isEmpty()).isPresent()) {
diff --git a/core/net/src/main/java/org/onosproject/net/intent/impl/phase/Failed.java b/core/net/src/main/java/org/onosproject/net/intent/impl/phase/Failed.java
index 0a05e4f..26ba858 100644
--- a/core/net/src/main/java/org/onosproject/net/intent/impl/phase/Failed.java
+++ b/core/net/src/main/java/org/onosproject/net/intent/impl/phase/Failed.java
@@ -33,8 +33,7 @@
      * @param data intentData
      */
     Failed(IntentData data) {
-        this.data = checkNotNull(data);
-        this.data.setState(FAILED);
+        this.data = IntentData.nextState(checkNotNull(data), FAILED);
     }
 
     @Override
diff --git a/core/net/src/main/java/org/onosproject/net/intent/impl/phase/Withdrawn.java b/core/net/src/main/java/org/onosproject/net/intent/impl/phase/Withdrawn.java
index b51f1f7..2e8e67a 100644
--- a/core/net/src/main/java/org/onosproject/net/intent/impl/phase/Withdrawn.java
+++ b/core/net/src/main/java/org/onosproject/net/intent/impl/phase/Withdrawn.java
@@ -33,8 +33,7 @@
      * @param data intent data containing an intent to be withdrawn
      */
     Withdrawn(IntentData data) {
-        this.data = checkNotNull(data);
-        this.data.setState(WITHDRAWN);
+        this.data = IntentData.nextState(checkNotNull(data), WITHDRAWN);
     }
 
     @Override