ONOS-6613 Non-disruptive intent reallocation

Change-Id: I5d051c20402a226ad540b8bc08695b602ff75273
diff --git a/core/api/src/main/java/org/onosproject/net/intent/IntentData.java b/core/api/src/main/java/org/onosproject/net/intent/IntentData.java
index 71c2ebf..bb7a710 100644
--- a/core/api/src/main/java/org/onosproject/net/intent/IntentData.java
+++ b/core/api/src/main/java/org/onosproject/net/intent/IntentData.java
@@ -450,6 +450,13 @@
                 return false;
             }
             // FALLTHROUGH
+        case REALLOCATING:
+            if (currentState == REALLOCATING) {
+                log.trace("{} update not acceptable: no-op REALLOCATING", newData.key());
+                return false;
+            } else if (currentState == INSTALLED) {
+                return true;
+            }
         case INSTALLED:
             if (currentState == INSTALLED) {
                 return false;
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 bc30408..47aa94d 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
@@ -63,7 +63,12 @@
         /**
          * Signifies that an intent has been purged from the system.
          */
-        PURGED
+        PURGED,
+
+        /**
+         * Signifies that an intent is being reallocated.
+         */
+        REALLOCATING
     }
 
     /**
@@ -118,6 +123,9 @@
             case INSTALLED:
                 type = Type.INSTALLED;
                 break;
+            case REALLOCATING:
+                type = Type.REALLOCATING;
+                break;
             case WITHDRAW_REQ:
                 type = Type.WITHDRAW_REQ;
                 break;
diff --git a/core/api/src/main/java/org/onosproject/net/intent/IntentState.java b/core/api/src/main/java/org/onosproject/net/intent/IntentState.java
index 88c76e4..2c75e7f 100644
--- a/core/api/src/main/java/org/onosproject/net/intent/IntentState.java
+++ b/core/api/src/main/java/org/onosproject/net/intent/IntentState.java
@@ -16,6 +16,7 @@
 package org.onosproject.net.intent;
 
 import com.google.common.annotations.Beta;
+import org.onosproject.net.intent.constraint.NonDisruptiveConstraint;
 
 /**
  * Representation of the phases an intent may attain during its lifecycle.
@@ -113,5 +114,15 @@
      * in WITHDRAWN or FAILED.
      * </p>
      */
-    PURGE_REQ
+    PURGE_REQ,
+
+    /**
+     * Indicates that the intent is being reallocated in a non-disruptive way {@link NonDisruptiveConstraint}.
+     * This state can be used to inform other applications that the intent is performing
+     * the reallocation. In particular type of networks this operation can require
+     * a long time. After all the reallocation stages are completed, the intent
+     * returns to the {@link #INSTALLED} state. If any of the reallocation stages fails,
+     * the intent is flagged as {@link #FAILED}.
+     */
+    REALLOCATING
 }
diff --git a/core/api/src/main/java/org/onosproject/net/intent/constraint/NonDisruptiveConstraint.java b/core/api/src/main/java/org/onosproject/net/intent/constraint/NonDisruptiveConstraint.java
new file mode 100644
index 0000000..4e5fb6b
--- /dev/null
+++ b/core/api/src/main/java/org/onosproject/net/intent/constraint/NonDisruptiveConstraint.java
@@ -0,0 +1,59 @@
+/*
+ * Copyright 2017-present Open Networking Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.onosproject.net.intent.constraint;
+
+import org.onosproject.net.intent.ConnectivityIntent;
+import org.onosproject.net.intent.Intent;
+
+/**
+ * Constraint to request a non-disruptive intent reallocation.
+ */
+public final class NonDisruptiveConstraint extends MarkerConstraint {
+
+    private static final NonDisruptiveConstraint NON_DISRUPTIVE_CONSTRAINT = new NonDisruptiveConstraint();
+
+    protected NonDisruptiveConstraint() {
+    }
+
+    /**
+     * Determines whether the intent requires a non-disruptive reallocation.
+     *
+     * @param intent  intent to be inspected
+     * @return        whether the intent has a NonDisruptiveConstraint
+     */
+    public static boolean requireNonDisruptive(Intent intent) {
+        if (intent instanceof ConnectivityIntent) {
+            ConnectivityIntent connectivityIntent = (ConnectivityIntent) intent;
+            return connectivityIntent.constraints().stream()
+                    .anyMatch(p -> p instanceof NonDisruptiveConstraint);
+        }
+        return false;
+    }
+
+    /**
+     * Returns the nonDisruptiveConstraint.
+     *
+     * @return non-disruptive constraint
+     */
+    public static NonDisruptiveConstraint nonDisruptive() {
+        return NON_DISRUPTIVE_CONSTRAINT;
+    }
+
+    @Override
+    public String toString() {
+        return "Non-disruptive reallocation required";
+    }
+}