Initial work on Intent API (ONOS-618)

Change-Id: I2b4aa0befabbf0b4dce8b2c991e38411709b2e80
diff --git a/core/api/src/main/java/org/onosproject/net/intent/Intent.java b/core/api/src/main/java/org/onosproject/net/intent/Intent.java
index e44690b..19170ae 100644
--- a/core/api/src/main/java/org/onosproject/net/intent/Intent.java
+++ b/core/api/src/main/java/org/onosproject/net/intent/Intent.java
@@ -34,7 +34,10 @@
 public abstract class Intent {
 
     private final IntentId id;
+
     private final ApplicationId appId;
+    private final String key;
+
     private final Collection<NetworkResource> resources;
 
     private static IdGenerator idGenerator;
@@ -45,6 +48,7 @@
     protected Intent() {
         this.id = null;
         this.appId = null;
+        this.key = null;
         this.resources = null;
     }
 
@@ -54,11 +58,26 @@
      * @param appId         application identifier
      * @param resources     required network resources (optional)
      */
+    @Deprecated
     protected Intent(ApplicationId appId,
                      Collection<NetworkResource> resources) {
+        this(appId, null, resources);
+    }
+
+        /**
+         * Creates a new intent.
+         *
+         * @param appId         application identifier
+         * @param key           optional key
+         * @param resources     required network resources (optional)
+         */
+    protected Intent(ApplicationId appId,
+                     String key,
+                     Collection<NetworkResource> resources) {
         checkState(idGenerator != null, "Id generator is not bound.");
         this.id = IntentId.valueOf(idGenerator.getNewId());
         this.appId = checkNotNull(appId, "Application ID cannot be null");
+        this.key = (key != null) ? key : id.toString(); //FIXME
         this.resources = checkNotNull(resources);
     }
 
diff --git a/core/api/src/main/java/org/onosproject/net/intent/IntentBatchDelegate.java b/core/api/src/main/java/org/onosproject/net/intent/IntentBatchDelegate.java
index a2eceb6..0c53262 100644
--- a/core/api/src/main/java/org/onosproject/net/intent/IntentBatchDelegate.java
+++ b/core/api/src/main/java/org/onosproject/net/intent/IntentBatchDelegate.java
@@ -18,6 +18,7 @@
 /**
  * Facade for receiving notifications from the intent batch service.
  */
+@Deprecated
 public interface IntentBatchDelegate {
 
     /**
diff --git a/core/api/src/main/java/org/onosproject/net/intent/IntentBatchLeaderEvent.java b/core/api/src/main/java/org/onosproject/net/intent/IntentBatchLeaderEvent.java
index b434218..793653c 100644
--- a/core/api/src/main/java/org/onosproject/net/intent/IntentBatchLeaderEvent.java
+++ b/core/api/src/main/java/org/onosproject/net/intent/IntentBatchLeaderEvent.java
@@ -21,6 +21,7 @@
 /**
  * A class to represent an intent related event.
  */
+@Deprecated
 public class IntentBatchLeaderEvent extends AbstractEvent<IntentBatchLeaderEvent.Type, ApplicationId> {
 
     public enum Type {
diff --git a/core/api/src/main/java/org/onosproject/net/intent/IntentBatchListener.java b/core/api/src/main/java/org/onosproject/net/intent/IntentBatchListener.java
index c4a4637..5365e29 100644
--- a/core/api/src/main/java/org/onosproject/net/intent/IntentBatchListener.java
+++ b/core/api/src/main/java/org/onosproject/net/intent/IntentBatchListener.java
@@ -20,5 +20,6 @@
 /**
  * Listener for {@link org.onosproject.net.intent.IntentEvent intent events}.
  */
+@Deprecated
 public interface IntentBatchListener extends EventListener<IntentBatchLeaderEvent> {
 }
diff --git a/core/api/src/main/java/org/onosproject/net/intent/IntentBatchService.java b/core/api/src/main/java/org/onosproject/net/intent/IntentBatchService.java
index bf8e4fd..4494f26 100644
--- a/core/api/src/main/java/org/onosproject/net/intent/IntentBatchService.java
+++ b/core/api/src/main/java/org/onosproject/net/intent/IntentBatchService.java
@@ -22,6 +22,7 @@
 /**
  * Service for tracking and delegating batches of intent operations.
  */
+@Deprecated
 public interface IntentBatchService {
 
     /**
diff --git a/core/api/src/main/java/org/onosproject/net/intent/IntentOperation.java b/core/api/src/main/java/org/onosproject/net/intent/IntentOperation.java
index c73199e..afb0010 100644
--- a/core/api/src/main/java/org/onosproject/net/intent/IntentOperation.java
+++ b/core/api/src/main/java/org/onosproject/net/intent/IntentOperation.java
@@ -29,6 +29,7 @@
     private final Type type;
     private final IntentId intentId;
     private final Intent intent;
+    //FIXME consider pulling the key out (we will hash based on key)
 
     /**
      * Operation type.
@@ -47,11 +48,13 @@
         /**
          * Indicates that an intent should be replaced with another.
          */
+        @Deprecated
         REPLACE,
 
         /**
          * Indicates that an intent should be updated (i.e. recompiled/reinstalled).
          */
+        @Deprecated
         UPDATE,
     }
 
diff --git a/core/api/src/main/java/org/onosproject/net/intent/IntentOperations.java b/core/api/src/main/java/org/onosproject/net/intent/IntentOperations.java
index 176ac85..2f30fa4 100644
--- a/core/api/src/main/java/org/onosproject/net/intent/IntentOperations.java
+++ b/core/api/src/main/java/org/onosproject/net/intent/IntentOperations.java
@@ -31,6 +31,7 @@
 /**
  * Batch of intent submit/withdraw/replace operations.
  */
+@Deprecated
 public final class IntentOperations {
 
     private final List<IntentOperation> operations;
diff --git a/core/api/src/main/java/org/onosproject/net/intent/IntentService.java b/core/api/src/main/java/org/onosproject/net/intent/IntentService.java
index 2b92bf8..3c1c91a 100644
--- a/core/api/src/main/java/org/onosproject/net/intent/IntentService.java
+++ b/core/api/src/main/java/org/onosproject/net/intent/IntentService.java
@@ -48,6 +48,7 @@
      * @param oldIntentId identifier of the old intent being replaced
      * @param newIntent new intent replacing the old one
      */
+    @Deprecated
     void replace(IntentId oldIntentId, Intent newIntent);
 
     /**
@@ -59,6 +60,7 @@
      * </p>
      * @param operations batch of intent operations
      */
+    @Deprecated
     void execute(IntentOperations operations);
 
     /**
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 0deabad..e4d7423 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
@@ -37,7 +37,7 @@
      * This is a transitional state after which the intent will enter either
      * {@link #FAILED} state or {@link #INSTALLING} state.
      */
-    COMPILING,
+    COMPILING, //TODO do we really need this?
 
     /**
      * Signifies that the resulting installable intents are being installed
diff --git a/core/api/src/main/java/org/onosproject/net/intent/IntentStore.java b/core/api/src/main/java/org/onosproject/net/intent/IntentStore.java
index ea60d7c..534279b 100644
--- a/core/api/src/main/java/org/onosproject/net/intent/IntentStore.java
+++ b/core/api/src/main/java/org/onosproject/net/intent/IntentStore.java
@@ -73,4 +73,22 @@
      */
     List<Operation> batchWrite(BatchWrite batch);
 
+    /**
+     * Adds a new operation, which should be persisted and delegated.
+     *
+     * @param op operation
+     */
+    default void add(IntentOperation op) {} //FIXME remove when impl.
+
+    /**
+     * Checks to see whether the calling instance is the master for processing
+     * this intent, or more specifically, the key contained in this intent.
+     *
+     * @param intent intent to check
+     * @return true if master; false, otherwise
+     */
+    //TODO better name
+    default boolean isMaster(Intent intent) { //FIXME remove default when impl.
+        return true;
+    }
 }
diff --git a/core/api/src/main/java/org/onosproject/net/intent/IntentStoreDelegate.java b/core/api/src/main/java/org/onosproject/net/intent/IntentStoreDelegate.java
index bd2e6f5..ab56c99 100644
--- a/core/api/src/main/java/org/onosproject/net/intent/IntentStoreDelegate.java
+++ b/core/api/src/main/java/org/onosproject/net/intent/IntentStoreDelegate.java
@@ -21,4 +21,12 @@
  * Intent store delegate abstraction.
  */
 public interface IntentStoreDelegate extends StoreDelegate<IntentEvent> {
+
+    /**
+     * Provides an intent operation that should be processed (compiled and
+     * installed) by this manager.
+     *
+     * @param op    intent operation
+     */
+    void process(IntentOperation op);
 }
diff --git a/core/net/src/main/java/org/onosproject/net/intent/impl/IntentManager.java b/core/net/src/main/java/org/onosproject/net/intent/impl/IntentManager.java
index 8280b02..8703e01 100644
--- a/core/net/src/main/java/org/onosproject/net/intent/impl/IntentManager.java
+++ b/core/net/src/main/java/org/onosproject/net/intent/impl/IntentManager.java
@@ -380,6 +380,11 @@
         public void notify(IntentEvent event) {
             eventDispatcher.post(event);
         }
+
+        @Override
+        public void process(IntentOperation op) {
+            //FIXME
+        }
     }
 
     private void buildAndSubmitBatches(Iterable<IntentId> intentIds,